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

10
function createMarker(latlng, item) {
    var marker = new google.maps.Marker({
        position: latlng,
        map: map
    });

这段代码的一部分。在网站上它显示为标准标记,大家都喜欢它,只是有点红。我怎样才能将其改成另一种颜色呢?

https://yadi.sk/i/ZDONpfoijAjdZ

1个回答

34

您应该使用icon属性。例如,

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

在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


来自谷歌的一些例子:

(要获取图像URL,请将鼠标悬停在其上或使用右键单击 → “复制图像位置”等)

64×64px

32×32像素

12×20px

更多内容请访问:https://sites.google.com/site/gmapsdevelopment/ 或者 搜索 获取更多信息。


10
你可以在 https://sites.google.com/site/gmapsdevelopment/ 和 https://gist.github.com/VarunDT/20514fd365a5c27d344a93dada33a690 找到可用图标的列表。 - jarmod
自定义标记似乎会强制生成一个可点击的矩形区域,因此无法手动添加靠近标记的其他标记。 - George Birbilis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接