我正在尝试使用 V3 MarkerClusterer 功能。
从我的数据库加载和解析 XML 没问题,但集群器不在我的阵列上工作?
我只是让我所有的标记一直显示!
任何帮助表示赞赏。
<script type="text/javascript">
var map;
var marker;
var markerArray = [];
function initialize() {
var myLatlng = new google.maps.LatLng(0.00,-8.6130819);
var myOptions = {
zoom: 2,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.SATELLITE
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var infoWindow1 = new google.maps.InfoWindow;
var infoWindow = new google.maps.InfoWindow
// PHP file to parse and retrieve database points
downloadUrl("/php/Ventus_application2.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("CARMA");
for (var i = 0; i < markers.length; i++) {
var MTCPERYEAR = markers[i].getAttribute("MTCPERYEAR");
var PLANT = markers[i].getAttribute("PLANT");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("LAT")),
parseFloat(markers[i].getAttribute("LON")));
var html = "<b> Total CO2 emissions: </b> " + MTCPERYEAR + "<b> Mega Tons </b><br/><br/>"+"<b> Plant Name: </b>"+ PLANT;
var html1 = PLANT;
marker = new google.maps.Marker({
map: map,
position: point,
draggable: true,
icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
});
//marker array to allow clearin markers
markerArray.push(marker);
bindInfoWindow(marker, map, infoWindow1, html1);
bindInfoWindow(marker, map, infoWindow, html);
<!-- Add a listener for drag event and return lat and long -->
google.maps.event.addListener(marker, 'dragend', function (event) {
document.getElementById("LAT").value = this.getPosition().lat();
document.getElementById("LON").value = this.getPosition().lng();
});
google.maps.event.addListener(marker, 'click', function() {
document.getElementById("PLANT").value = infoWindow1.getContent();
});
}
var markerCluster = new MarkerClusterer(map, markerArray);
});
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {};
}
</script>