简体   繁体   中英

Google Maps 3.46 not removing markers from map

This use to work but now when I clear my markers and add new ones, the old ones still appear. I am not sure why and have tried about everything. My clear code, map link is below. If you click say Baseball first as a sport and search, than Futsal , search, you will notice the markers stay.

You can use Inspect in Chrome and follow the app.map.j s file and see how it works but the Javascript file link is also below.

function clearOverlays() {
    for (var i = 0; i < self.markers.length; i++) {
        google.maps.event.clearInstanceListeners(self.markers[i]);
        self.markers[i].setMap(null);
    }

    self.markers.length = 0;
    self.markers = new Array();
}

Map Link

Javascript

I just reviewed your codes for remove markers on the map now, I think this issue happened because markers array was not deleted Could you send me whole codes including HTML files?

To disappear all your markers, you should call the function with null:

// Removes the markers from the map, but keeps them in the array.
  function clearMarkers() {
    setMapOnAll(null);
  }

And, to remove and disappear, all your markers, you should reset your array of markers like this:

// Deletes all markers in the array by removing references to them.
  function deleteMarkers() {
    clearMarkers();
    markers = [];
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM