要打開一個對話框,而不是一個信息窗口,在代碼中註釋掉該行:
bindInfoWindow(marker, map, infoWindow, html);
,並用此替代它:
$('<div>').html(html).dialog();
爲了實現MarkerClusterer
,更新了代碼:
var mc = new MarkerClusterer(map);
mc.addMarker(marker);
完全load()
功能:
function load() {
var dialog = $('<div>').dialog({autoOpen:false});
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(47.6145, -122.3418),
zoom: 13,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
var mc = new MarkerClusterer(map);
// Change this depending on the name of your PHP file
downloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
mc.addMarker(marker);
//bindInfoWindow(marker, map, infoWindow, html);
google.maps.event.addListener(marker, 'click', function() {
dialog.html(html).dialog('open');
});
}
});
}
http://code.google.com/apis/maps/articles/phpsqlsearch.html你不使用PHP喜歡它需要輸出的XML例如,如果你只是有一個靜態的xml文件,它仍然是一個教程,你可以看看。 – 2011-06-13 18:50:04