我想从我的谷歌地图中删除一个标记,但我似乎无法让它工作。我找到了各种答案,都告诉我.setMap(null)
在标记上使用,但我似乎无法让它工作。
$map_canvas = $('#map_canvas');
var youreHere_Marker;
function centerMapToAddress( address ) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if( typeof youreHere_Marker!=="undefined"){
youreHere_Marker.setMap(null);
}
youreHere_Marker = $map_canvas.gmap('addMarker', {'position': results[0].geometry.location.lat()+','+results[0].geometry.location.lng(), 'bounds': true});
}
});
}
我明白了TypeError: youreHere_Marker.setMap is not a function
。据我所知,这意味着该变量youreHere_Marker
没有方法.setMap()
,但如果我这样做console.log(youreHere_Marker)
并检查对象,我可以看到方法。
我的地图上有更多标记,通过MarkerClusterer
. 那些应该保持不变
我有一种接近的感觉,有人能指出我正确的方向吗?
编辑:我也试过.setPosition()
,同样的错误。我假设我使用的变量不正确,但我不知道如何正确引用它。