在Google地图上放一些不同颜色的点

时间:2018-06-28 04:52:14

标签: javascript google-maps google-maps-api-2

我想将三个点放在 lat long google地图中,但我希望每个点都有不同的颜色。
这是我的代码,此代码目前为所有点设置一种颜色

    function initMap() {

        map = new google.maps.Map(document.getElementById('map'), {
            zoom: 11,
            center: {lat: 39.585938, lng: 47.909219}
        });

        heatmap = new google.maps.visualization.HeatmapLayer({
            data: getPoints(),
            map: map
        });

        var gradient = [
            'rgba(255, 0, 0, 0)',
            'rgba(255, 0, 0, 1)'
        ]
        heatmap.set('gradient', gradient);
    }

    function getPoints() {
        return [
            new google.maps.LatLng(39.585938, 47.909219,20),
            new google.maps.LatLng(39.585938, 47.909220,20),
            new google.maps.LatLng(39.585938, 47.909221,20),
            new google.maps.LatLng(39.585938, 47.909222,20),
        ];
    }

1 个答案:

答案 0 :(得分:0)

您可以使用strokeColor属性定义自定义标记:

示例:

strokeColor: "red",

参考:https://developers.google.com/maps/documentation/javascript/markers

var marker = new google.maps.Marker({
    id: "some-id",
    icon: {
        path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
        strokeColor: "red",
        scale: 3
    },
    map: map,
    title: "Any-title",
    position: myLatlng
});

参考文献: https://developers.google.com/maps/documentation/javascript/symbols