Remove all gmaps markers on jquery delete button

I am using jquery-UI map for gmaps and I want to make a popup when I click maps on gmaps.

 $(function() {             
                $('#map_canvas').gmap( {'center': new google.maps.LatLng(-0.789275, 113.921327), 'callback': function(map) {
                        $(map).click( function(event) {
                            $('#map_canvas').gmap('addMarker', {'position': event.latLng, 'title': '', 'draggable': true, 'bound': false}, function(map, marker) {
                            $('#test').dialog({'modal':true, 'title': 'Edit and save point', 'buttons': {
                            "Remove": function() {
                                $(this).dialog( "close" );
                               $(map).setMap(null);
                            },
                            "Save": function() {
                                $(this).dialog( "close" );
                            }
                        }});
                                findLocation(marker.getPosition(), marker);
                            }).dragend( function(event) {
                                var self = this;
                                findLocation(event.latLng, this);
                            }).click( function() {
                                openDialog(this);
                            })
                        });
                    }});

I want to remove all markers when I click the delete button in this code:

 "Remove": function() {
                            $(this).dialog( "close" );
                           $(map).setMap(null);}

But the marker still remains, someone please help me. Thanks you

+5
source share
3 answers

You have to call

$('#map_canvas').gmap('clearMarkers');
+6
source

in version 3 of the plugin should use:

$('#map_canvas').gmap('clear', 'markers');
+17
source

Haven't worked with this plugin before, but a quick look at the API docs seems to suggest that this might work:

"Remove": function() {
       $(this).dialog( "close" );
       $(map).clearMarkers();
}
0
source

All Articles