gpt4 book ai didi

javascript - 谷歌地图 : set custom color for type of markers

转载 作者:行者123 更新时间:2023-11-28 20:04:24 25 4
gpt4 key购买 nike

我正在尝试在 Google map 中设置彩色标记,以便每个位置类型都有自己的颜色。

var markers = [
['Buy Jeans', latitude,logitude,'store'],
['Eat well', latitude,logitude,'restaurant'],
['Get drunk', latitude,logitude,'bar']
];

下面是我们如何运行可用标记。但我不知道如何给予“存储”红色别针,“餐厅”蓝色别针并“禁止”绿色图钉

for( i = 0; i < markers.length; i++ ) {
var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][0],
});

有没有办法根据markers[i][3]在for循环中设置图标?

最佳答案

我解决了这个问题:

if(markers[i][3] == "store") { showIcon = "http://maps.google.com/mapfiles/ms/icons/red-dot.png"; }
if(markers[i][3] == "restaurant") { showIcon = "http://maps.google.com/mapfiles/ms/icons/blue-dot.png"; }
if(markers[i][3] == "bar") { showIcon = "http://maps.google.com/mapfiles/ms/icons/green-dot.png"; }

marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][0],
icon: showIcon
});

关于javascript - 谷歌地图 : set custom color for type of markers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21081778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com