Javascript Google Maps API V3 Places库无法读取属性';地点';未定义的
所以我在Chrome中使用Google Maps API V3,并尝试使用Place库向我的地图添加感兴趣的点。除了在setMarker方法中,我从以下行获得一个错误Javascript Google Maps API V3 Places库无法读取属性';地点';未定义的,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,所以我在Chrome中使用Google Maps API V3,并尝试使用Place库向我的地图添加感兴趣的点。除了在setMarker方法中,我从以下行获得一个错误位置:place.geometry.location,错误无法读取未定义的属性“location” 您正在使用setMarker()函数从传递整个结果对象的Places回调中创建标记。但是将LatLng对象传递给执行setMarker(fim)操作的同一个函数 不使用相同的功能,您只需执行以下操作: new google.m
位置:place.geometry.location
,错误无法读取未定义的属性“location”
您正在使用setMarker()
函数从传递整个结果对象的Places回调中创建标记。但是将LatLng
对象传递给执行setMarker(fim)
操作的同一个函数
不使用相同的功能,您只需执行以下操作:
new google.maps.Marker({
map: mapp,
position: fim
});
而不是setMarker(fim)代码>我知道,我已经看了很多例子,至少它们是一样的。我将在调用API和Places库的地方放一行(可能有什么地方出错了…)有没有办法将LatLng
对象转换为方法以便它工作?因此,我不必仅为LatLng
对象创建另一个setMarker
函数。。。
fim = new google.maps.LatLng(-33.8665433, 151.1956316);
setMarker(fim);
setMarker(results[i]);
function setMarker(place) {
var marker = new google.maps.Marker({
map: mapp,
position: place.geometry.location
});
}
new google.maps.Marker({
map: mapp,
position: fim
});