Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图:为标记类型设置自定义颜色_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 谷歌地图:为标记类型设置自定义颜色

Javascript 谷歌地图:为标记类型设置自定义颜色,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我试图在谷歌地图中设置彩色标记,这样每个位置类型都有自己的颜色 var markers = [ ['Buy Jeans', latitude,logitude,'store'], ['Eat well', latitude,logitude,'restaurant'], ['Get drunk', latitude,logitude,'bar'] ]; 下面是我们如何浏览可用标记的。但我不知道如何给予 “储存”一枚红色别针, “餐厅”蓝色别针 还有一个绿色的

我试图在谷歌地图中设置彩色标记,这样每个位置类型都有自己的颜色

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],
});
for(i=0;i

是否有任何方法可以基于标记[i][3]在for循环中设置图标?

您需要使用符号的fillColor属性将图标属性添加到标记选项中


您需要使用符号的fillColor属性将图标属性添加到标记选项中


您需要使用符号的fillColor属性将图标属性添加到标记选项中


您需要使用符号的fillColor属性将图标属性添加到标记选项中


我用以下方法解决了问题:

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
});

我用以下方法解决了问题:

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
});

我用以下方法解决了问题:

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
});

我用以下方法解决了问题:

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
});

谢谢你的努力,扎克。我几分钟前解决了它,并将解决方案添加到我的问题中。你不应该将你的解决方案添加到你的问题中,而应该将其作为答案发布,并将其标记为AcceptedHanks,我不知道。将其添加为答案,并在可能的情况下接受它。谢谢你的努力,扎克。我几分钟前解决了它并将答案添加到我的问题中。与其将你的答案添加到你的问题中,不如将其作为答案发布,并将其标记为已接受。Hanks,我不知道。将其添加为答案,并在可能时接受。感谢Zach的努力。我几分钟前解决了它,并将答案添加到我的问题中。而不是添加yo您的问题解决方案,您应该将其作为自己的答案发布,并将其标记为AcceptedHanks,不知道。将其作为答案添加,并在可能时接受。感谢Zach的努力。我几分钟前解决了它,并将解决方案添加到我的问题中。您应该将其作为ans发布,而不是将您的解决方案添加到您的问题中wer自己,并将其标记为AcceptedHanks,不知道。将其添加为答案,并在可能时接受。