how to get all markers on google-maps-v3

前端 未结 6 2053
南方客
南方客 2020-12-05 01:51

Is there a way to get all the markers on Google Maps?

相关标签:
6条回答
  • 2020-12-05 01:56

    If you mean "how can I get a reference to all markers on a given map" - then I think the answer is "Sorry, you have to do it yourself". I don't think there is any handy "maps.getMarkers()" type function: you have to keep your own references as the points are created:

    var allMarkers = [];
    ....
    // Create some markers
    for(var i = 0; i < 10; i++) {
        var marker = new google.maps.Marker({...});
        allMarkers.push(marker);
    }
    ...
    

    Then you can loop over the allMarkers array to and do whatever you need to do.

    0 讨论(0)
  • 2020-12-05 02:03

    I'm assuming you have multiple markers that you wish to display on a google map.

    The solution is two parts, one to create and populate an array containing all the details of the markers, then a second to loop through all entries in the array to create each marker.

    Not know what environment you're using, it's a little difficult to provide specific help.

    My best advice is to take a look at this article & accepted answer to understand the principals of creating a map with multiple markers: Display multiple markers on a map with their own info windows

    0 讨论(0)
  • 2020-12-05 02:15

    If you are using JQuery Google map plug-in then below code will work for you -

    var markers = $('#map_canvas').gmap('get','markers');

    0 讨论(0)
  • 2020-12-05 02:17

    Google Maps API v3:

    I initialized Google Map and added markers to it. Later, I wanted to retrieve all markers and did it simply by accessing the map property "markers".

    var map = new GMaps({
        div: '#map',
        lat: 40.730610,
        lng: -73.935242,
    });
    
    var myMarkers = map.markers;
    

    You can loop over it and access all Marker methods listed at Google Maps Reference.

    0 讨论(0)
  • 2020-12-05 02:19

    The one way found is to use the geoXML3 library which is suitable for usage along with KML processor Version 3 of the Google Maps JavaScript API.

    0 讨论(0)
  • 2020-12-05 02:20

    For an specific cluster use: getMarkers() Gets the array of markers in the clusterer.

    For all the markers in the map use: getTotalMarkers() Gets the array of markers in the clusterer.

    0 讨论(0)
提交回复
热议问题