Board index JavaServer Faces General Use p:gmap with address.

Use p:gmap with address.

Components, Ajax Framework, Utilities and More.

Post 17 Jan 2012, 13:44

Posts: 73
Location: São Paulo - Brasil
Hello !

Anyone know if there is a way to use "p:gmap" passing an address and not only the longitude and latitudes ?

Like this component of IceFaces:
http://comp-suite.icefaces.org/comp-suite/showcase.jsf?grp=compatMenu&exp=map

I searched in forum and issue, but found nothing equal.

Thanks.
Mojarra 2.1.22, Facelets, Glassfish V3.1.2.2, Primefaces 4.0-SNAPSHOT, NetBeans 7.3.1

Nei Alcantara Jr.
http://twitter.com/NeiAlcantaraJr

Post 24 Jan 2012, 18:25

Posts: 1
I also am in need of such an implementation would be very cool

Post 24 Jan 2012, 21:25

Posts: 5955
Go to Issue 3220 in Issue Tracker, click Star (as that casts your vote for this new feature to be added to PrimeFaces, and to be updated via email about this issue/feature request).
Howard

PrimeFaces 5.1, Extensions 2.1.0, Push (Atmosphere 2.2.3)
TomEE+ 1.7.1 (Tomcat 7.0.55), MyFaces Core 2.2.5, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post 24 Jan 2012, 21:35

Posts: 73
Location: São Paulo - Brasil
Hello smithh032772

Very good. I'll vote, thanks !!
Mojarra 2.1.22, Facelets, Glassfish V3.1.2.2, Primefaces 4.0-SNAPSHOT, NetBeans 7.3.1

Nei Alcantara Jr.
http://twitter.com/NeiAlcantaraJr

Post 24 Jan 2012, 23:59

Posts: 265
It would be very handsome, especially receiving geocoding informations.

But there is an jsf implementation already out there, so maybe no need to reinvent the wheel, but I did not tested it yet.

http://code.google.com/p/gmaps4jsf/

But since Google Geocoding informations should be retrievied by client and not a server (recommend by google), Javascript is the way to go here.
(Google will block you if your server has too many requests!, using client side request you can avoid this)

In my case I only use it inside an admin panel to retrieve coordinates and save them to database, so it would be handsome using it serverside.

Just call the google api and save the lat and lng in (hidden) fields which are attached to a bean.


Here extract of my function code. For better usage I have one client marker reference which is updated with new location upon a search and I pass a callback function to open a confirm dialog to confirm the found location.

var geocoder = new google.maps.Geocoder();

function geocodeAddress(inputAddressId, inputLatId, inputLngId, coordMaxFractDigits, map)
{
   var inputAddress = document.getElementById(inputAddressId);

   geocoder.geocode({'address': inputAddress.value}, function(results, status)
   {
      if(status == google.maps.GeocoderStatus.OK)
      {
         if(results.length > 0)
         {
            if(results.length > 1)
            {
               alert("Multiple addresses found for given input.")
               //do something
            }
         
            //set name of address text field, direct usage
            inputAddress.value = String(results[0].address_components[0].long_name);
            
            var latLng = results[0].geometry.location;
         
            //set lat and lng text fields
            document.getElementById(inputLatId).value = round(parseFloat(latLng.lat()), coordMaxFractDigits).toLocaleString();
            document.getElementById(inputLngId).value = round(parseFloat(latLng.lng()), coordMaxFractDigits).toLocaleString();
         
            map.setCenter(latLng);
         
            var viewport = results[0].geometry.viewport;
            map.setZoom(10 - Math.round(Math.log(Math.abs(viewport.getSouthWest().lng() - viewport.getNorthEast().lng()))/Math.log(2)));
         }
      }
   });
}



Call it something like:

<h:form>
   <p:gmap id="cityMap"/>
   <p:inputText id="name" .../>
   <h:inputHidden id="lat" .../>
   <h:inputHidden id="lng" .../>
   <p:commandButton ... onclick="geocodeAddress(\'#{component.parent.findComponent('name').clientId}\',
      \'#{component.parent.findComponent('lat').clientId}\',
      \'#{component.parent.findComponent('lng').clientId}\',
      5,
      #{p:widgetVar('cityMap')}.getMap())"/>
</h:form>



Maybe the now lat and lng values can be reset into center attribute of gmap for autofocus.
Last edited by djmj on 22 Jun 2012, 02:02, edited 7 times in total.
Primefaces: 5.0
Primefaces-Mobile: 0.9.4
Jsf: Mojarra 2.2.4
Server: Glassfish Web 4.0

Post 25 Jan 2012, 02:29

Posts: 5955
djmj wrote:
Here extract of my function code. For better usage I have one client marker reference which is updated with new location upon a search.


Thanks for sharing your code. What about using geocoder (client javascript) with p:autoComplete or p:inputText, start typing address, and geocoder does similar to p:autoComplete?
Howard

PrimeFaces 5.1, Extensions 2.1.0, Push (Atmosphere 2.2.3)
TomEE+ 1.7.1 (Tomcat 7.0.55), MyFaces Core 2.2.5, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post 25 Jan 2012, 04:09

Posts: 265
I don't see how that should be working, since autocomplete is using server side bean for auto suggestion.

Maybe send the Json response to the bean and populate a list, or maybe it is possible to extract just the names of all found locations. But if it is just for autocomplete feature I don't see much sense in communicating with the server.
Primefaces: 5.0
Primefaces-Mobile: 0.9.4
Jsf: Mojarra 2.2.4
Server: Glassfish Web 4.0

Post 25 Jan 2012, 04:29

Posts: 5955
That might work. Good thought/idea.

Earlier you mentioned that google recommends javascript client code, but I think I researched this, and I think I saw that REST webservice is available for geocoder, for those interested in server-side solution that could possibly populate p:autoComplete. At some point, I'd like to research this and try it. I think I bookmarked it in my Chrome browser.
Howard

PrimeFaces 5.1, Extensions 2.1.0, Push (Atmosphere 2.2.3)
TomEE+ 1.7.1 (Tomcat 7.0.55), MyFaces Core 2.2.5, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post 25 Jan 2012, 11:25

Posts: 15080
Location: Cybertron

PrimeFaces Lead

Post 25 Jan 2012, 13:00

Posts: 73
Location: São Paulo - Brasil
Hello optimus.prime,
On the issue in 1629, says he would be ready in version 3.0, 3.0-RC1 and Future of primefaces, but have no implementation so.
You know when that will be implemented?

Thanks.
Mojarra 2.1.22, Facelets, Glassfish V3.1.2.2, Primefaces 4.0-SNAPSHOT, NetBeans 7.3.1

Nei Alcantara Jr.
http://twitter.com/NeiAlcantaraJr

Next

Return to General