Skip to content Skip to sidebar Skip to footer

Get Total Marker Count From Google Api Placessearch

In the example fiddle, how can I get the total number of markers displayed on the map? I'm pushing each of the markers into an array like this: markers.push(marker) And attempting

Solution 1:

the placesSearch call is asynchronous, when you run your code:

$('.marker-count span').html(markers.length);

the result hasn't come back from the server yet. You need to do that in the call back after you update the markers array.

functioncallback(results, status) {
          if (status == google.maps.places.PlacesServiceStatus.OK) {
            for (var i = 0; i < results.length; i++) {
              createMarker(results[i]);
            }
            $('#map-canvas').attr("data-markers",results.length);
            $('.marker-count span').html(markers.length);                  
          } else {
            console.log("Places request failed: "+status);
          }
        } // end callback

working fiddle

Post a Comment for "Get Total Marker Count From Google Api Placessearch"