如何更改标记颜色?谷歌地图

Mas*_*nin 4 google-maps-markers

function createMarker(latlng, item) {
    var marker = new google.maps.Marker({
        position: latlng,
        map: map
    });
Run Code Online (Sandbox Code Playgroud)

这部分代码.在网站上它显示为标准标记,它适合我们所有人,但红色.如何将其更改为其他颜色?

https://yadi.sk/i/ZDONpfoijAjdZ

Yel*_*yev 25

你应该使用icon财产.例如,

var marker = new google.maps.Marker({
    position: latlng,
    map: map,
    icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
});
Run Code Online (Sandbox Code Playgroud)

google.com上有许多颜色可供选择.只需green-dot用你的颜色替换:

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

  • 您可以在https://sites.google.com/site/gmapsdevelopment/和https://gist.github.com/VarunDT/20514fd365a5c27d344a93dada33a690找到可用图标列表. (10认同)