Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all gmaps marker on jquery remove button

I use jquery-UI-map for gmaps, and i want to make popup when i click the 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 marker when i click remove button in this code :

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

But the marker still remain, someone please help me. Thank you

like image 360
Bijak Antusias Sufi Avatar asked Jul 20 '11 02:07

Bijak Antusias Sufi


2 Answers

in plugin version 3 one should use:

$('#map_canvas').gmap('clear', 'markers');
like image 77
Gatis Bergšpics Avatar answered Oct 04 '22 13:10

Gatis Bergšpics


You should call

$('#map_canvas').gmap('clearMarkers');
like image 43
johansalllarsson Avatar answered Oct 04 '22 11:10

johansalllarsson