按位置将标记计数添加到GMap

时间:2016-08-05 19:40:50

标签: javascript google-maps

我希望为地图上的每个位置添加标记计数。您会注意到地图上显示的三个地方都有不同数量的标记:

Here's my jsfiddle.

如果您可以关注它,可以使用以下代码:

function initialize() {

    var locations = [
        [40.82829, -73.9271, 'Marker 1'],
        [40.756421, -73.845897, 'Marker 2'],
        [40.756421, -73.845897, 'Marker 3'],
        [40.750704, -73.993752, 'Marker 4'],
        [40.750704, -73.993752, 'Marker 5'],
        [40.750704, -73.993752, 'Marker 6']
    ];

    var map = new google.maps.Map(document.getElementById("map-canvas"), {
        zoom: 12,
        center: new google.maps.LatLng(40.773522, -73.944039),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    // Create markers on the map
    for (var i = 0; i < locations.length; i++) {
        var pos = new google.maps.LatLng(locations[i][0], locations[i][1]); 

        var marker = new google.maps.Marker({
            position: pos,
            map: map,
            title: locations[i][2]
        });
    }
}

initialize();

我想在每个标记下方的div中显示计数。

0 个答案:

没有答案