谷歌地图集群和richamaker

时间:2014-11-21 02:22:20

标签: javascript google-maps google-maps-api-3 markerclusterer

问题是谷歌地图的集群和ruby on rails上的richmarker

大家好,我是google地图的新手。 最近我正在使用Ruby on Rails开发一个Web应用程序, 昨天我发现了一个至关重要的问题,这是我的javascript:

//Build initialize Gmap and build markers on it
//initialize array
var map_infos = [];
//receive marker data from controller
map_infos = gon.map_infos; 

function initialize() {
    var mapOptions = {
        zoom: 8,
        center: new google.maps.LatLng(25.026, 121.523)
    };

    var map = new google.maps.Map(document.getElementById('map'), mapOptions);

//rmarker setting
    var rmarkers = [];
    for(var i = 0; i < map_infos.length; i++){
    var rmarker = new RichMarker({
        position: new google.maps.LatLng(
            map_infos[i]["marker_lat"], 
            map_infos[i]["marker_lng"]
        ),
        content: '<div class="marker_background"><img src="'+map_infos[i]["friend_icon"]+'" class="friend_icon" /></div>',
        map: map
    }).setShadow('5px -3px 3px #555');
    rmarkers.push(rmarker);
    }
    var markerCluster = new MarkerClusterer(map, rmarkers);
}

google.maps.event.addDomListener(window, 'load', initialize);

但是在上面的情况下集群功能不起作用! 它仍然显示每一个标记!

所以我将richmarker更改为google默认标记,如下所示:

var rmarker = new google.maps.Marker({
    for(var i = 0; i < map_infos.length; i++){
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(
        map_infos[i]["marker_lat"], 
        map_infos[i]["marker_lng"]
    ),
    map: map
    });
    markers.push(marker);
    }
    var markerCluster = new MarkerClusterer(map, rmarkers);
});

群集现在正在运作!

所以问题是:

如何在此期间使用richmarker和cluster?

感谢阅读和考虑

1 个答案:

答案 0 :(得分:0)

我只是尝试做同样的事情,并通过使用以下代码(在Angular中,但应该与您相似)让它工作第一次可能你需要将更多属性传递给RichMarker?

$scope.markerClusterer = new MarkerClusterer($scope.map, $scope.dynMarkers, {
            gridSize: 25
        });

然后:

{{1}}