0
votes

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 ?

2

2 Answers

1
votes

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"}}
],
0
votes

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