使用PrimeFaces p:gmap組件。如何將地址解析器地址獲取到支持bean?
我有一個帶有一組標記的gmap組件的頁面。
我想在gmapInfoWindow中顯示街道地址,並將它傳遞給backing bean。 當我點擊地圖標記時,我調用一個javascript函數來獲取反向地理編碼器地址。 我可以獲取地址並將其顯示在JavaScript警告對話框中,但我無法將其填充到支持bean變量或info標記中。
變量確實被填充,但直到下次單擊標記時纔會更新。 因此,地址始終是一個標記點擊後面。
有誰知道我可以如何獲取地址在當前頁面會話期間更新? 謝謝。
MapMarkerSelect上的支持bean代碼只有一個System.out.println語句來顯示mapAddress變量。
這裏是頁面代碼:
<h:form prependId="false" >
<p:gmap id="gmap" center="#{mappingSessionBean.mapCenter}" zoom="#{mappingSessionBean.mapZoom}" type="HYBRID" rendered="true"
style="#{mappingSessionBean.polygonGmapStyle}" onPointClick="handlePointClick(event);"
model="#{mappingSessionBean.mapModel}" fitBounds="#{mappingSessionBean.fitBoundsFlag}"
widgetVar="map" >
<p:ajax id="gmapAjax" event="overlaySelect" immediate="true" onstart="handlePointClick(event);" listener="#{mappingSessionBean.onMapMarkerSelect}" />
<p:gmapInfoWindow id="infoWindow" >
<p:outputPanel >
<h:panelGrid columns="1" >
<h:outputText id="infoWindowTitle" value="#{mappingSessionBean.selectedMarker.title}" />
<h:outputText id="infoWindowAddress" value="#{mappingSessionBean.mapAddress}" rendered="true" />
<p:commandButton value="Zoom In" action="#{mappingSessionBean.selectedViewInfoListener}" update="gmap" />
</h:panelGrid>
</p:outputPanel>
</p:gmapInfoWindow>
</p:gmap>
<h:inputHidden id="address" value="#{mappingSessionBean.mapAddress}" />
</h:form >
<script type="text/javascript" >
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('address').value = results[0].formatted_address;
document.getElementById('infoWindowAddress').value = results[0].formatted_address;
}
else
{
alert("Geocoder failed due to: " + status);
}
});
}
else
{
alert("No Geolocation");
}
}
</script>