我正在尝试删除像这样初始化的标记:
marker = new google.maps.Marker({
position: latLng,
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
title: 'Marker 1',
icon: redPin
});
google.maps.event.addListener(marker, "click", function() {
showMarkerDialog(marker.position, "marker");
});
google.maps.event.addListener(marker, "dblclick", function() {
// Add a alert: Are you sure you want to remove this marker?
map.removeOverlay(marker);
});
除了当我双击它以删除我在错误控制台上获得的内容时,一切都很完美:
TypeError:Object#没有方法'removeOverlay'
我做错了什么?
答案 0 :(得分:66)
map 对象上没有 removeOverlay 函数。听起来你只有一个标记,为什么要使用数组呢?只需改变一下:
google.maps.event.addListener(marker, "dblclick", function() {
map.removeOverlay(marker);
});
到此:
marker.addListener("dblclick", function() {
marker.setMap(null);
});