0

I am currently developing a small app on top of Gmap3 & GoogleMaps I am not by far a javascript specialist although I have some experience

My data set comes from a JS file which I parse into a data[] array where one can find for each marker lat,lng,title,(infowindow)content,icon to be used

all of this works a treat except one, the icon color

This works :

var thiscolor ='green'; // forces all icons to be green not what I want but it works

.....

icon : new google.maps.MarkerImage('img/marker'+thiscolor+'.png',null, null, null, new google.maps.Size(25,25 )) ...

This doesn't :

icon : new google.maps.MarkerImage('+data.icon+',null, null, null, new google.maps.Size(25,25 ))

where I could verify that data.icon is parsed correctly and shows: img/markergreen.png or img/markerred.png

I have been trying all sorts of implicit,explicit single & double quotes and + sign combinations around the icon file path ......

:-( to now avail

aaaaaarg getting mad anyone can help ?

Community
  • 1
  • 1

2 Answers2

1

You must send markers in below format:-

markers:[
    {lat:48.8620722, lng:2.352047, data:'Paris !', options:{icon:"http://maps.google.com/mapfiles/marker_purple.png"}},
    {lat:46.59433,lng:0.342236, data:'Poitiers : great city !'},
    {lat:42.704931, lng:2.894697, data:'Perpignan ! <br> GO USAP !', options:{icon: "http://maps.google.com/mapfiles/marker_green.png"}}
],
Surinder
  • 106
  • 4
0

you can use setIcon method to set the Icon for a marker

marker1.setIcon("img/marker'+thiscolor+'.png");

For reference http://googlemaps.googlermania.com/google_maps_api_v3/en/change_icon_of_marker.html

Ramesh Kotha
  • 8,266
  • 17
  • 66
  • 90
  • Thanks for that try , but the question was more around understanding the difference in syntax between 'forced' icon which works and 'data driven' icon which doesn't. The method works, simply the syntax is wrong in the latter case – user1256021 May 11 '12 at 08:34