我正在使用“google places 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' and 'arguments' are restricted function properties and cannot be accessed in this context.
at Function.remoteFunction (:3:14)
at Object.InjectedScript.callFunctionOn (:750:66)
最佳答案
我遇到了同样的问题。我的 Lat 和 Lng 似乎是函数,但也是错误的。 为了获得实际值,您必须实际调用 lat 和 long 作为函数并将其分配给回调中的变量。
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
}
});
关于javascript - 谷歌放置 api 不返回几何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33093465/