本文介绍了在Google Maps API v3中删除标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试删除已被初始化的 marker :
marker = new google.maps.Marker({
position:latLng,
map:map,
draggable:true,
animation:google.maps.Animation.DROP,
标题:'标记1',
图标:redPin
});
google.maps.event.addListener(marker,click,function(){
showMarkerDialog(marker.position,marker);
});
google.maps.event.addListener(marker,dblclick,function(){
//添加提醒:您确定要移除此标记吗?
map.removeOverlay(marker);
});
除了当我双击它以删除我在错误控制台上得到的东西时, :
$ b
我做错了什么?
解决方案
没有 removeOverlay 功能 map 对象。听起来你只有一个标记,为什么要使用数组?只需改变它:
google.maps.event.addListener(marker,dblclick,function(){
map.removeOverlay(marker);
}); b
marker.addListener(dblclick,function(){
marker.setMap(null);
});
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:
What am I doing wrong?
解决方案
There is no removeOverlay function on the map object. 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);
});
这篇关于在Google Maps API v3中删除标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!