1

I currently use this script:

<script src="http://maps.google.com/maps/api/js?sensor=false" 
      type="text/javascript"></script>

<div id="map" style="width: 800px; height: 800px;"></div>          

<script type="text/javascript">
var locations = [
  ['info1', 46.780961,6.64018],
  ['info2', 46.511102,6.493958],
  ['info3', 46.516786,6.629087],
  ['info4', 46.442796,6.895498],
  ['info5', 46.463002,6.843443]
];

var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 10,
  center: new google.maps.LatLng(46.519962,6.633597),
  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>

I dont use php/mysql but html, because the map is realy simple (only five locations) and will never change.

What i want is to add a DIFFERENT picture (like that: https://i.stack.imgur.com/GFfzy.jpg) for each marker.

Is that possible?

I'm not developer and I have no idea how to do.

Thanks for your help!

Kara
  • 6,115
  • 16
  • 50
  • 57
zed
  • 11
  • 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 Jun 24 '13 at 20:49

2 Answers2

1

You can specify the URL of the image when creating a marker like this:

var image = {
    url: thumbnailUrl,
    size: new google.maps.Size(20, 20),
    origin: new google.maps.Point(0,0),
    anchor: new google.maps.Point(10, 10)
};

marker = new google.maps.Marker({
    icon: image,
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map
});
Dmitry Trofimov
  • 503
  • 4
  • 10
1

The problem here is javascript closure.

So instead of doing

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

you should do

google.maps.event.addListener(marker, 'click', 
     (function (localMarker, location) {
         return function () { 
                 infowindow.setContent(location);
                 infowindow.open(map, localMarker); 
         };
     })(marker, locations[i][0]));
Vadim
  • 21
  • 1
  • 3