0

How can i add customize icon to highlight lakshadweep beach in below mentioned code.

As i have only basic java knowledge, so please provide easy method so that i can edit and apply the same on other projects.

here is my complete code..

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <script src="http://maps.google.com/maps/api/js?sensor=false" 
          type="text/javascript"></script>

</head>

<body>
<div id="map" style="width: 100%; height: 400px;"></div>
<script>
var locations = [
  ['lakshadweep Beach', 10.204729,72.836778, 4],
  ['Coogee Beach', -33.923036, 151.259052, 5],
  ['Cronulla Beach', -34.028249, 151.157507, 3],
  ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
  ['Maroubra Beach', -33.950198, 151.259302, 1]

];

var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 3,
  center: new google.maps.LatLng(-10.90, 100.25),
  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>
Hetal
  • 9
  • 3
  • 1
    possible duplicate of [Colour the first marker of a Google Map a different colour](http://stackoverflow.com/questions/16900210/colour-the-first-marker-of-a-google-map-a-different-colour) – geocodezip Mar 10 '15 at 09:41
  • Thx a lot @ geocodezip ...its working... – Hetal Mar 10 '15 at 10:58

2 Answers2

0

Please add these lines in your code.

var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/'; // image path

var marker = new google.maps.Marker({
  position: myLatLng,
  map: map,
  icon: iconBase + 'schools_maps.png'
});

it's work for me..

geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • Thanks sanjay and geocodezip but it's change all the icons. I want to change only lakshadweep icon. :( – Hetal Mar 10 '15 at 10:20
0

update these lines in your code.

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

}
else
{
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map
  });
}
geocodezip
  • 158,664
  • 13
  • 220
  • 245