[英]Removing a Marker in Google Maps API v3
I'm trying to remove a marker that was initialized like this: 我正在尝试删除像这样初始化的标记 :
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);
});
Everything works perfectly except that when I double click it to remove what I get on the Error Console is this: 一切都很完美,除了当我双击它以删除我在错误控制台上得到的是这样的:
TypeError: Object # has no method 'removeOverlay' TypeError:Object#没有方法'removeOverlay'
What am I doing wrong? 我究竟做错了什么?
There is no removeOverlay function on the map object. 地图对象上没有removeOverlay函数。 Sounds like you've got only one marker, why use an array? 听起来你只有一个标记,为什么要使用数组呢? Just change this: 只需改变这个:
google.maps.event.addListener(marker, "dblclick", function() {
map.removeOverlay(marker);
});
to this: 对此:
marker.addListener("dblclick", function() {
marker.setMap(null);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.