2016-09-07 72 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

相關問題