标记群集在具有精确坐标时仅显示一个标记

时间:2015-07-23 07:45:23

标签: google-maps-api-3

这是我的小提琴

http://jsfiddle.net/6wp7enot/12/

var map = null;
var markerArray = []; //create a global array to store markers
var myPoints = [
    [43.65654, -79.90138, 'ABC'],
    [43.65654, -79.90138, 'DEF'],
    [43.65654, -79.90138, 'GHA']
]; //create global array to store points

function initialize() {
    var myOptions = {
        zoom: 8,
        center: new google.maps.LatLng(43.907787, -79.359741),
        mapTypeControl: true,
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
        },
        navigationControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var mcOptions = {
        gridSize: 50,
        maxZoom: 15
    };
    var mc = new MarkerClusterer(map, [], mcOptions);

    google.maps.event.addListener(map, 'click', function() {
        infowindow.close();
    });


    for (var i = 0; i < myPoints.length; i++) {
        createMarker(new google.maps.LatLng(myPoints[i][0], myPoints[i][1]), myPoints[i][2]);
    }

    mc.addMarkers(markerArray, true);
}

var infowindow = new google.maps.InfoWindow({
    size: new google.maps.Size(150, 50)
});

function createMarker(latlng, html) {
    var contentString = html;
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        zIndex: Math.round(latlng.lat() * -100000) << 5
    });


    markerArray.push(marker); //push local var marker into global array
}

window.onload = initialize;

你能告诉我如何处理这个

1 个答案:

答案 0 :(得分:0)

您在同一位置创建了所有三个标记,表示相同的纬度和经度。所以三个标记只在一个地方创建。请更改阵列中其他两个元素的纬度和经度。 例如。 var myPoints = [ [43.65654, -79.90138, 'ABC'], [44.65654, -79.90138, 'DEF'], [45.65654, -79.90138, 'GHA'] ]; //create global array to store points