【发布时间】:2015-06-17 17:01:22
【问题描述】:
请帮忙!我的针太多了,而且还在增长!
这是我用来在 www.findmyfields.com 的地图上放置图钉的代码。此代码有效(您可以在网站上看到)。
非工作版本位于http://reddirtsoftball.com/map/maptest.php。
<script>
function initialize() {
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId: 'roadmap'
};
// Display a map on the page
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
map.setTilt(45);
// Multiple Markers
var markers = [
//I have some php in here with a while loop that gets the info for the markers.
];
// Info Window Content
var infoWindowContent = [
//I have some php in here with a while loop that gets the info for the window content.
];
// Display multiple markers on a map
var infoWindow = new google.maps.InfoWindow(), marker, i;
// Loop through our array of markers & place each one on the map
for( i = 0; i < markers.length; i++ ) {
var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][0]
});
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent(infoWindowContent[i][0]);
infoWindow.open(map, marker);
}
})(marker, i));
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
}
// Override our map zoom level once our fitBounds function runs (Make sure it only runs once)
var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
this.setZoom(4);
google.maps.event.removeListener(boundsListener);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
我很难让 Map Clusterer 工作。
当我尝试添加聚类代码时(见下文)
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent(infoWindowContent[i][0]);
infoWindow.open(map, marker);
}
})(marker, i));
markers.push(marker);
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
// Override our map zoom level once our fitBounds function runs (Make sure it only runs once)
var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
this.setZoom(4);
google.maps.event.removeListener(boundsListener);
});
var markerCluster = new MarkerClusterer(map, markers);
}
整个网站被锁定并且永远不会加载。
【问题讨论】:
-
您可以查看 Google GitHub github.com/googlemaps/js-marker-clusterer 以了解如何实现标记集群
-
@Verma,相信我,我在 Github 上花了几天时间研究标记聚类器。他们只是不在我的网站上或我的代码上工作。
-
在其文档和 SO 上有使用 markerclusterer 的工作示例。请提供一个 Minimal, Complete, Tested and Readable example 来证明您尝试使用的代码不起作用。
-
@geocodezip 我希望我的“已编辑”问题更清楚
标签: google-maps-api-3 markerclusterer