-1

I'm using the following Code for creating my markers:

<pre>
    var marker = new google.maps.Marker({
        position: siteLatLng,
        map: map,
        icon: 'https://maps.google.com/mapfiles/kml/shapes/schools_maps.png',
        title: value2["title"],
        zIndex: 4,
        html: value2["content"]
    });
</pre>

Now I want to remove all Markers from my map, that was created by

<pre>
    var centerMap = new google.maps.LatLng(50, 10);
    var myOptions = {
        zoom: 4,
        center: centerMap,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById('gMapsPreview'), myOptions);
</pre>
Mustang96
  • 39
  • 1
  • 4
  • If you want to remove more than one marker that is created that way, you need to have a unique reference to it/them. – geocodezip Jun 19 '15 at 16:42

1 Answers1

0

Same problem here:

I've corrected it, change clearMarkers method this way:

set_map(null) ---> setMap(null)

google.maps.Map.prototype.clearMarkers = function() {
    for(var i=0; i < this.markers.length; i++){
        this.markers[i].setMap(null);
    }
    this.markers = new Array();
};

Documentation has been updated to include details on the topic: https://developers.google.com/maps/documentation/javascript/markers#remove

Community
  • 1
  • 1
Luca
  • 1,766
  • 3
  • 27
  • 38
  • thank you :) but next question: how to group the markers? i tried the script from the google documentation, but it didn't work... – Mustang96 Jun 19 '15 at 14:17
  • 1
    you can ask a new question on so and mark this one as answered :) than youll get some more help ^^ – Luca Jun 19 '15 at 14:54