【发布时间】:2016-05-21 06:43:16
【问题描述】:
我正在使用“谷歌地点自动完成 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)
【问题讨论】:
-
你的
search-btn是一个按钮? -
@MrNeo 这是一个文本框:
<input type="text" id="search-btn" placeholder="Search for more locations"/> -
我临时找到了一个解决方案,在我将 json 对象放入“place”变量后,我使用类似的位置地址从 google geocode api 请求 (lat,lng):
$.getJSON("https://maps.googleapis.com/maps/api/geocode/json?address=" + place.formatted_address + "&key=myKey", function (data, statue) { var geomtry_arr = [data['results'][0].geometry.location['lat'], data['results'][0].geometry.location['lng']];});
标签: javascript google-maps google-places-api