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'
What am I doing wrong?
When you use Google Maps to find a route to a destination, pins mark the starting point and the destination. Depending on the route, pins may also mark locations along the route, including detours. To remove any of these pins, right-click the Pin and select Remove this destination from the drop-down menu.
Find the “Layers” menu in the bottom left corner of the screen. Hover your cursor over the box and wait until more options appear. Click “More” to open the Map Details menu. Under “Map Type,” you'll see a checked box next to “Labels.” Uncheck it to remove all labels.
If you want to remove the pin from Google Maps, simply right click on it and select "Remove this destination." Poof, it's gone.
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); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With