Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript, Change google map marker color

May I know a way to change the Google Map marker color via Javascript.. I am new at this and any help would be much appreciated, Thank you.

I used the following code to create a marker

 marker = new google.maps.Marker({      position: new google.maps.LatLng(locations[i][1],       locations[i][2]),      animation: google.maps.Animation.DROP,      map: map  }); 
like image 326
Hasitha Shan Avatar asked Jun 16 '12 14:06

Hasitha Shan


People also ask

How do you change the color of a marker on Google Maps?

To edit the marker color, click or tap on the marker icon. When you do that, you can change both the color of the marker and its style. Go for the color or style you want to change and then click OK to see the effect. Click on the button labeled Done to save your new marker color settings.


1 Answers

In Google Maps API v3 you can try changing marker icon. For example for green icon use:

marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png') 

Or as part of marker init:

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

Other colors:

  • http://maps.google.com/mapfiles/ms/icons/blue-dot.png
  • http://maps.google.com/mapfiles/ms/icons/red-dot.png

Etc.

like image 167
jsalonen Avatar answered Oct 01 '22 19:10

jsalonen