Geocoding with Primefaces

Primefaces offers an official primefaces google maps implementation. With the new primefaces 5.1.2 it also allows you to use geocode with the following two new methods:
  • geocode(address)
  • reverseGeocode(lat, lng)

This is an example from the official primefaces showcase:
 <p:gmap id="geoGmap" widgetVar="geoMap" center="#{geocodeView.centerGeoMap}"type="ROADMAP" model="#{geocodeView.geoModel}">
    <p:ajax event="geocode" listener="#{geocodeView.onGeocode}" update="@this" />

The java code for the normal geocode request looks like this:
public void onGeocode(GeocodeEvent event) {
List<GeocodeResult> results = event.getResults();

if (results != null && !results.isEmpty()) {

 LatLng center = results.get(0).getLatLng();
 centerGeoMap = center.getLat() + "," + center.getLng();

 for (int i = 0; i < results.size(); i++) {

  GeocodeResult result = results.get(i);
  geoModel.addOverlay(new Marker(result.getLatLng(), result.getAddress()));



Continue reading here: http://blog.primefaces.org/?p=3339 

 If you have any questions, feel free to leave a comment.