-1
我想從MySql數據庫加載標記(我用一個PHP文件轉換數據給出XML輸出),但我只看到地圖。在閱讀StackOverflow上的文章後,我仍然不知道如何使它工作。GMaps顯示標記
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=true"></script>
</head>
<body>
<script>
function initialize()
{
var map=new google.maps.Map(document.getElementById("mapka"), {
center:new google.maps.LatLng(51.109612,17.036276),
zoom:12,
mapTypeId:google.maps.MapTypeId.ROADMAP
});
downloadUrl("dane.php", function(data)
{
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++)
{
var nazwa = markers[i].getAttribute("nazwa");
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var point = new google.maps.LatLng(lat,lng);
var marker = new google.maps.Marker({
map: map,
position: point
});
}
});
}
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() {}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="mapka" style="width:700px;height:500px;"></div>
</body>
</html>
的XML看起來是這樣的:
<dane>
<marker lat="51.110287" lon="17.062647" nazwa="Hello_1" address="Street_1"/>
<marker lat="51.111807" lon="17.058012" nazwa="Hello_2" address="Street_2"/>
</dane>
@ Dr.Molle,該解決方案不起作用 – Andrzej 2013-02-18 01:32:49
那麼你將不得不顯示你的函數'downloadUrl',因爲它沒有在代碼上面的代碼 – 2013-02-18 01:38:14
data.responseXML中包含什麼?當它不是XML文檔時,讓PHP腳本發送一個XML-content-type-header – 2013-02-18 01:59:22