Google地图:为标记类型设置自定义颜色 [英] Google Maps: set custom color for type of markers

查看:98
本文介绍了Google地图:为标记类型设置自定义颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to set colored markers in Google maps, so that every location type has its own color.

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

以下是我们如何运行可用的标记。但我不知道如何给
'store'一个红色的销,
'restaurant'一个蓝色的销
和'bar'一个绿色的销

Below is how we run through the available markers. But I can't figure out how to give 'store' a red pin, 'restaurant' a blue pin and 'bar' a green pin

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

有没有什么方法可以根据标记[i] [3 ]

Is there any way to set the icon in the for-loop based on markers[i][3]?

推荐答案

我解决了这个问题:

I solved the problem with:

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

这篇关于Google地图:为标记类型设置自定义颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆