title: Primefaces : get geocoder address from google Map to ManagedBean
body: <p>I want to pass the geocoder address from Google Map to ManagedBean, but I have to select twice on the map, I think because the method (onPointSelect) is executed before the address is passed to the ManagedBean</p>
  
  <p>ManagedBean : </p>
  
  <pre><code>private String mapAddress;
  
  public void onPointSelect(PointSelectEvent event) {
  
          LatLng latlng = event.getLatLng();
          setMapAddress(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("myForm:address"));
          addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Point Selected", "Lat:" + latlng.getLat() + ", Lng:" + latlng.getLng() + " Address: " + getMapAddress()));    
      }
  </code></pre>
  
  <p>XHTML : </p>
  
  <pre><code>       &lt;h:form id="myForm" &gt;
          &lt;p:growl id="messages" showDetail="true" life="2000"  /&gt;
  
          &lt;p:gmap center="41.381542, 2.122893" zoom="15" type="ROADMAP" widgetVar="map"  style="width:600px;height:400px" onPointClick="handlePointClick(event);" &gt;
  
              &lt;p:ajax event="stateChange"  listener="#{test.onStateChange}"  /&gt;
  
              &lt;p:ajax event="pointSelect"  listener="#{test.onPointSelect}"     update="messages" /&gt;
  
          &lt;/p:gmap&gt; 
          &lt;h:inputHidden  id="address" value="#{test.mapAddress}"/&gt;
      &lt;/h:form&gt;
  
      &lt;script type="text/javascript" &gt;
          //var ma = document.getElementById('myForm:address');
          function handlePointClick(event) {
  
              if (navigator.geolocation)
              {
                  browserSupportFlag = true;
                  var latlng = event.latLng;
                  geocoder = new google.maps.Geocoder();
                  geocoder.geocode({'latLng': latlng}, function(results, status)
                  {
                      if (status === google.maps.GeocoderStatus.OK)
                      {
                          //alert( results[0].formatted_address );
                          document.getElementById('myForm:address').value = results[0].formatted_address;
  
                          //jQuery("#address").val(results[0].formatted_address);
                          //jQuery("#addressBtn").click();
                          //alert( document.getElementById('myForm:address').value ); 
  
                      }
                  });
              }
          }
  
      &lt;/script&gt;
  </code></pre>