0
<!DOCTYPE html>
<html> 
<head> 
  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
  <title>Google Maps Multiple Markers</title> 
  <script src="http://maps.google.com/maps/api/js?sensor=false" 
    type="text/javascript"></script>
</head> 
<body>
  <div id="map" style="width: 600px; height: 800px;"></div>

  <script type="text/javascript">
    var locations = [
      ['address 1', latitude coordinate, longitude coordinate, 1],
      ['address 2', latitude coordinate, longitude coordinate, 2],
      ['address 3', latitude coordinate, longitude coordinate, 3],
      ...
      ['address 58', latitude coordinate, longitude coordinate, 58],
      ['address 59', latitude coordinate, longitude coordinate, 59],
      ['address 60', latitude coordinate, longitude coordinate, 60],
      ,
    ];

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 10,
      center: new google.maps.LatLng(47.594, -122.249),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
  </script>
</body>
</html>

Q (1): Can addresses 1-5 have a green pin/marker while addresses 6-60 remain the default red pin/marker?

Able to change all pins to green, yellow, etc. using,

marker = new google.maps.Marker({
  icon: 'http://...'
});

however that changes all rather than a select few (of pins/markers).

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
user01
  • 13
  • 3
  • Related question: [Display infowindow by default and different markers in Google Maps](http://stackoverflow.com/questions/16844370/display-infowindow-by-default-and-different-markers-in-google-maps/16844974#16844974) – geocodezip Aug 25 '15 at 05:13
  • possible duplicate of [How to change the image for a set of map markers](http://stackoverflow.com/questions/17539312/how-to-change-the-image-for-a-set-of-map-markers) – geocodezip Aug 25 '15 at 05:14
  • possible duplicate of [Google maps api v3 - multiple markers, multiple infowindows, 3 icons](http://stackoverflow.com/questions/2543971/google-maps-api-v3-multiple-markers-multiple-infowindows-3-icons) – geocodezip Aug 25 '15 at 05:16

1 Answers1

0

In Google Maps API v3 you could utilize setIcon function of google.maps.Marker class to set marker icon.

Example

var locations = [
     ['Interfaith Medical Center', 40.67836, -73.937781, 1],
     ['Kingsbrook Jewish Medical Center', 40.65935, -73.933232, 2],
     ['Kingsboro Psychiatric Center', 40.656192, -73.937523, 3],
     ['Kings County Hospital Center', 40.657201, -73.944647, 4],
     ['University Hospital of Brooklyn', 40.655378, -73.945763, 5],
     ['New York Methodist Hospital', 40.667098, -73.978336, 6],
     ['Brookdale University Hospital and Medical Center', 40.655411, -73.912418, 7],
     ['Wyckoff Heights Medical Center', 40.704148, -73.917607, 8],
     ['Woodhull Medical Center', 40.698731, -73.942759, 9],
     ['The Brooklyn Hospital Center', 40.690206, -73.97825, 10]
];

var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 12,
    center: new google.maps.LatLng(40.67836, -73.937781),
    mapTypeId: google.maps.MapTypeId.ROADMAP
});

var infowindow = new google.maps.InfoWindow();

var marker, i;

for (i = 0; i < locations.length; i++) {
    marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
    });

    if (i < 5) {  //set marker icon to green for the first 5 markers
        marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png');
    }

    google.maps.event.addListener(marker, 'click', (function (marker, i) {
        return function () {
            infowindow.setContent(locations[i][0]);
            infowindow.open(map, marker);
        }
    })(marker, i));
}
<script src="http://maps.google.com/maps/api/js?sensor=false"
            type="text/javascript"></script>
<div id="map" style="width: 600px; height: 480px;"></div>
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193