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.