2016-09-07 71 views
-2

我想使用PhoneGap获得准确的经度和纬度,但我无法获得准确的经度,长期它总是在小数点后第三个小时点波动意味着它给出了11m的差异,如下所述: 十进制 地方度距 - ----- ------- -------- 0 1 111 km 1 0.1 11.1 km 2 0.01 1.11 km 3 0.001 111 m 4 0.0001 11.1 m 5 0.00001 1.11 m我们如何才能在PhoneGap中获得准确的纬度,经度?

为了获得经纬度,我使用了gpsdetect插件的geolocation插件。

这里是代码: navigator.geolocation.getCurrentPosition(的onSuccess,onError的,{maximumAge:3000,超时:20000,enableHighAccuracy:真}); function onSuccess(position) { window.lat = position.coords.latitude; window.long = position.coords.longitude; var accuracy = position.coords.accuracy; var lat =(window.lat).toFixed(6); var long =(window.long).toFixed(6); document.getElementById('lat')。value = lat; document.getElementById('long')。value = long; document.getElementById('accuracy')。value = accuracy; } function onGPSError(e) { console.log(“Error:”+ e); }

使用此代码我得到(22.699737,75.867208),但实际上它是(22.699667,75.86729)。

我只想得到基于gps的位置,而不是来自蜂窝塔和wifi信号。

gps打开时,是否可以在手机上通过GPS获取位置?

+0

请告诉我们你有什么到目前为止已经试过。堆栈溢出不是一种代码编写服务,但如果你至少试图自己解决问题,人们愿意帮助你。另请参阅[如何创建一个最小,完整和可验证的示例](http://stackoverflow.com/help/mcve)和[如何提出一个好问题?](http://stackoverflow.com/help /如何对问)。 –

+0

navigator.geolocation.getCurrentPosition(onSuccess,onError,{maximumAge:3000,timeout:20000,enableHighAccuracy:true}) –

+0

感谢Martin使用:navigator.geolocation.getCurrentPosition(onSuccess,onError,{maximumAge:3000,timeout:20000 ,enableHighAccuracy:true})function onSuccess(position) { window.lat = position.coords.latitude; window.long = position.coords.longitude; var accuracy = position.coords.accuracy; var lat =(window.lat).toFixed(6); var long =(window.long)。toFixed(6); alert(lat +','+ long); }我想获得经纬度,只有当gps不是通过wifi或cell信号启用时,请提示我。 –

回答

0

你可以使用jQuery地理编码从地址获取纬度。

通过你的位置(地址)从GP &调用这个jquery函数,你会得到完美的拉特,长。

var geocoder = new google.maps.Geocoder();

geocoder.geocode({ 'address': address }, function (results, status) { 

    if (status == google.maps.GeocoderStatus.OK) { 
     map.setCenter(results[0].geometry.location); 
     var marker = new google.maps.Marker({ 
      map: map, 
      position: results[0].geometry.location, 
      title: results[0].formatted_address 
     }); 
     var infowindow = new google.maps.InfoWindow({ content: address }); 
     infowindow.open(map, marker); 
     google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker); }); 
    } 
    else{ 
     alert("Problem with geolocation"); 
    } 
}); 

转换地址,以纬度经度: https://github.com/dhavaldenny/mapgeocodeangular

相关问题