【发布时间】:2012-08-11 16:57:48
【问题描述】:
我正在使用Google Maps Utility Library v3 在 Google 地图上尝试聚类标记的基本实现。
但是,当我运行它时,我在 Chrome 开发者工具控制台上收到一个错误:
Uncaught TypeError: Object #<Object> has no method 'getPosition'
这与实用程序库脚本中的第 649 行有关:http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js。以下是哪个函数:
/**
* Determins if a marker is contained in a bounds.
*
* @param {google.maps.Marker} marker The marker to check.
* @param {google.maps.LatLngBounds} bounds The bounds to check against.
* @return {boolean} True if the marker is in the bounds.
* @private
*/
MarkerClusterer.prototype.isMarkerInBounds_ = function(marker, bounds) {
return bounds.contains(marker.getPosition());
};
我使用的代码是相当标准的谷歌地图,主要功能是:
function initialize(items,loop,zoom) {
geocoder = new google.maps.Geocoder();
if (items.length > 0) {
var latlng = new google.maps.LatLng(items[0].Lat, items[0].Lng);
var myOptions = {
zoom: zoom,
center: latlng,
//mapTypeControl: false,
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
map.setOptions({styles: stylez});
for (var i = 0; i < items.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(items[i].Lat, items[i].Lng),
title: items[i].Title,
icon: _iconCenter,
shadow: shadow,
infocontent: items[i].Description
});
marker.setMap(map);
markersArray.push(marker);
}
var markerCluster = new MarkerClusterer(map, items);
google.maps.event.addListener(map, "tilesloaded", function () {
if(loop == true){
SetLoop();
}
});
}
}
据我所知,我已经追溯了错误函数,它应该接收地图边缘的坐标以便能够确定边界,这应该只是标准行为,但显然有些地方不对。
我想知道是否有人可以对此有所了解?
感谢大家的指点...
【问题讨论】:
标签: google-maps google-maps-api-3 google-maps-markers markerclusterer