0

i am using google geocode for displaying markers based on site name on google maps and it's working fine. now, i have situation where i have two same site name and chart only display one marker. it's overrides the marker. so, i think of clusters but, i don't know how to implement in my below code?.please help me

<script>
$(document).ready(function () {
var map;
var elevator;
var myOptions = {
    zoom: 4,
    center: new google.maps.LatLng(39.639537564366684, -97.03125),
    mapTypeId: 'terrain'
};
map = new google.maps.Map($('#map')[0], myOptions);

//info window
var infowindow = new google.maps.InfoWindow({});

var addresses = [<?php $numItems = count($val); $i=0; foreach($val as $data){ echo "['".$data['name']."','".$data['resp']."']"; if(++$i !== $numItems) {echo ",";}}?>];
//var colordot =[];
//alert(addresses);
for (var x = 0; x < addresses.length; x++) {
//alert(addresses[x][1]);
var resp = addresses[x][1];

            //alert(colordot[x]);
    $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address=' + addresses[x][0] + '&sensor=false', null, function(resp) {
      return function(data) {
        var p = data.results[0].geometry.location;
        var address = data.results[0].formatted_address;
        var latlng = new google.maps.LatLng(p.lat, p.lng);
        if (resp >= 50) {

                 var img= 'img/red-dot.png';
            }
            else{
                var img= 'img/green-dot.png';
            }
        var marker = new google.maps.Marker({

          icon: img,

          position: latlng,
          map: map
        });


        // Adding a click event to the marker
        google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent('<div><strong>SiteName : ' + address + '</strong><br><strong>Avg. Response : ' + resp + '</strong>');
            infowindow.open(map, this);
        });

      }
    }(resp));
}

});
</script>
Divyesh Jesadiya
  • 1,105
  • 4
  • 30
  • 68

1 Answers1

0

I think what you mean is that you have 2 markers right on top of each other because they share the exact same coordinates, and you want to indicate that they're indeed separate markers.

If this is the case, use MarkerClusterer https://developers.google.com/maps/documentation/javascript/marker-clustering

pscl
  • 3,322
  • 25
  • 29