我正在努力使用Google Maps API V3使用MarkerClusterer V3群集50个标记。

我遵循了一个简单的示例: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/examples.html 但是,要构建我的功能,在加载地图时,我在Firebug中遇到以下错误:

a is undefined
Ba(H,function(a){if(!a)return l;return...){return new P(this.T.d,this.P.b,i)}; main.js (line 13)

我的功能只是做一个简单的JSON调用以从服务器中获取点,然后在将标记数组添加到MarkerClusterer之前构建标记数组。

function addMarkerCluster(){
    //get json data and create array of map markers and mark up the map using
    //a map cluster

    $.getJSON("feed/kml.php?action=json",
        function(data){

            var map;
            var markers = [];

            var latlng = new google.maps.LatLng(24.91654, 15.31326);

            var myOptions = {
                zoom: 3,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.HYBRID

            };
            map = new google.maps.Map(document.getElementById("googlemap"), myOptions);

            google.maps.event.addListener(map, "tilesloaded", function(){
                attachFancyBox();
                hideLoadDialog();
            });


            //loop through the data and add to the markers array the lat/lng of the centerpoints
            //as google lat/lng objects.
            $.each(data, function(i){

                latlng = new google.maps.LatLng(this.lat, this.lng);
                var marker = new google.maps.Marker(latlng);

                markers.push(marker);

            });



            var markerCluster = new MarkerClusterer(map, markers);


        });


}

知道为什么这会导致Google Map main.js以这种方式失败?如果我只添加MarkerClusterer,而没有标记数组,则地图呈现没有错误。

当我添加标记数组时,则地图错误。

谢谢,

授予

有帮助吗?

解决方案

修复很简单,我会错过这样一个事实,即Google Maps API V3需要传递一个对象。解决方案是改变

var marker = new google.maps.Marker(latlng) 
to
var marker = new google.maps.Marker({'position' : latlng});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top