【问题标题】:markercluster and google maps v3 error "a is undefined"markercluster 和谷歌地图 v3 错误“a 未定义”
【发布时间】:2011-06-12 12:35:56
【问题描述】:

我正在努力尝试使用 markerclusterer v3 和 Google maps API 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,则地图呈现时不会出现错误。

当我添加标记数组时,地图就会出错。

谢谢,

授予

【问题讨论】:

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


    【解决方案1】:

    修复很简单我会错过谷歌地图 api v3 需要将对象传递给它的事实。解决方法是改变

    var marker = new google.maps.Marker(latlng) 
    to
    var marker = new google.maps.Marker({'position' : latlng});
    

    【讨论】:

    • +1 谢谢 .. 我需要更新我的插件 .. 你能说一下你在什么来源找到了解决方案(网页、论坛..)
    • 这是一个反复试验和阅读+重新阅读谷歌地图文档的过程。
    猜你喜欢
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多