![](/img/trans.png)
[英]I'm trying to add GPS functionality to my android app, gps coordinates come out to 0.0, 0.0 every time
[英]Primefaces geocode getting 0.0, 0.0 gps coordinates from backing bean
我想获取使用primefaces地理编码由地理编码服务生成的点的纬度和经度,但我遇到了麻烦。 但是,当我尝试从支持bean中获取这些坐标时,我会收到0.0值。
如何在它们具有适当值(登录到控制台后立即)而不是零的时间内访问它们?
请注意,我是Spring和PF的新手。
这是我的素面前端,我想在其中访问支持Bean类的适当变量值:
<script type="text/javascript">
function geocode() {
PF('geoMap').geocode(document.getElementById('address').value);
}
</script>
<h:form prependId="false">
<h3 style="margin-top:0">Geocode</h3>
<h:panelGrid columns="3" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel for="address" value="Address:" />
<p:inputText id="address" />
<p:commandButton value="Geocode" icon="ui-icon-search" onclick="geocode()" type="button" />
</h:panelGrid>
<p:gmap id="geoGmap" widgetVar="geoMap" center="#{geocodeView.centerGeoMap}" zoom="2" type="ROADMAP" model="#{geocodeView.geoModel}" style="width:100%;height:400px">
<p:ajax event="geocode" listener="#{geocodeView.onGeocode}" update="@this" />
</p:gmap>
<!-- Here for example I want to show this values -->
<p:commandButton value="Show values" action="" update="display" oncomplete="PF('dlg').show()" />
<p:dialog header="Value" modal="true" resizable="false" showEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<h:outputText value="Latitude: #{geocodeView.latitude}" />
<h:outputText value="Longitude: #{geocodeView.longitude}" />
</h:panelGrid>
</p:dialog>
</h:form>
并支持bean类:
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import org.primefaces.event.map.GeocodeEvent;
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.GeocodeResult;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;
@ManagedBean
public class GeocodeView {
private MapModel geoModel;
private String centerGeoMap = "41.850033, -87.6500523";
private double latitude;
private double longitude;
@PostConstruct
public void init() {
geoModel = new DefaultMapModel();
}
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);
Marker currentMarker = new Marker(result.getLatLng(), result.getAddress());
geoModel.addOverlay(currentMarker);
// Here are problematic values
latitude = currentMarker.getLatlng().getLat();
longitude = currentMarker.getLatlng().getLng();
System.out.println(latitude);
System.out.println(longitude);
}
}
}
public MapModel getGeoModel() {
return geoModel;
}
public String getCenterGeoMap() {
return centerGeoMap;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
}
在支持bean中添加geoModel的设置器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.