我碰到一個緯度給出的位置和經度:谷歌地理編碼器將返回來自請求的值不同的緯度和經度
getLocationFromCoords(lat, lng) {
var geocoder = new google.maps.Geocoder();
var latLng = new google.maps.LatLng(parseFloat(lat), parseFloat(lng));
geocoder.geocode({
'latLng': latLng
}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (typeof results[0].geometry.location != 'undefined') {
console.log(lat, lng);
console.log(results[0].geometry.location.lat(), results[0].geometry.location.lng());
// set the location
} else {
//...
}
});
});
}
的問題是,從results[0].geometry.location
緯度和經度從值不同請求。上面的代碼顯示在控制檯:
38.9067339 1.4205983
38.9069681 1.4205133000000387
所以我錯過了什麼?爲什麼不是相同的值?
什麼你想幹什麼? LatLong地址或LatLong地址? –
@TuğcaEker - LatLong地址(它也包含經緯度)。 – Manolo
好的。您正在申請**反向地理編碼**將座標轉換爲地址。您無法獲得完全相同的GeoLocation,因爲Google會向您返回最近的記錄。作爲一個檢查,預期和結果之間只有20-30米。別擔心,這很正常。 –