[英]Google places api not returning geometry
我正在使用“ google place autocomplete API”來使用類似的javascript獲取有關不同城市的數據:
var service = new google.maps.places.Autocomplete(document.getElementById('search-btn'));
service.addListener('place_changed', function () {
var place = service.getPlace();
console.log(place.geometry.location);
});
問題:對象不具有(lat,lng)但它具有此消息
TypeError:“ caller”和“ arguments”是受限制的函數屬性,在此上下文中無法訪問。
在Function.remoteFunction(:3:14)
在Object.InjectedScript.callFunctionOn(:750:66)
我似乎也有同樣的問題。 地圖工作正常,昨天返回了幾何圖形,今天它只是空白,沒有經度/緯度,並且存在相同的錯誤。
似乎他們更新了API,但出現了問題
編輯:
對我來說,它可以通過獲取標記坐標來解決,而不是嘗試對其進行地址解析,然后再獲取地址的后代。
我有這樣的代碼(工作12.10.15):
function geocodePosition(pos)
{
geocoder = new google.maps.Geocoder();
geocoder.geocode
({
latLng: pos
},
function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
$("#address").val(results[0].formatted_address);
$("#id_location_0").val(results[0].geometry.location.J);
$("#id_location_1").val(results[0].geometry.location.M);
}
}
);
}
此人停止工作,但能夠通過從標記中獲取坐標來進行修復。 Pos變量在我的情況下是marker.getPosition()。
if (status == google.maps.GeocoderStatus.OK)
{
$("#address").val(results[0].formatted_address);
$("#id_location_0").val(marker.position.lat());
$("#id_location_1").val(marker.position.lng());
}
似乎已報告https://code.google.com/p/gmaps-api-issues/issues/detail?id=8734
您可以嘗試:
var service = new google.maps.places.Autocomplete(document.getElementById('search-btn'));
service.addListener('place_changed', function () {
var place = service.getPlace();
console.log(place.geometry.location.lat(), place.geometry.location.lng());
});
我有同樣的問題。 我的Lat和Lng似乎是函數,但也有錯誤。 為了獲得實際值,您必須實際調用lat和long as函數,並將其分配給回調中的變量。
geocoder = new google.maps.Geocoder();
geocoder.geocode({'address' : addressString}, function(results, status){
if(status == google.maps.GeocoderStatus.OK){
///~~~~~~~~~The part you care about ~~~~~~~~~~///
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
console.log(lat); // --> 37.7603726
console.log(lng); // --> -122.47157
}
});
臨時解決方案:
var lat = results[0]['geometry']['location'].lat();
var lng = results[0]['geometry']['location'].lng();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.