我想从我的Google地图中移除一个标记,但似乎无法使其工作。我找到了各种答案,都告诉我在标记上使用.setMap(null)
,但我似乎无法使其工作。删除/移动Google地图标记(jquery-ui-maps)
$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()
,同样的错误。我假设我使用的变量不正确,但我不知道如何正确引用它。
你能做一个小提琴吗? –
不是,这是一个更大的项目,这是相关部分。这添加了我想要移除的一个标记。 – Martijn