你好女士和紳士,解析XML的谷歌地圖,以創建多個標記
今天的問題是這樣的:
GDownloadUrl("http://www.mysite/map.php",
function(data) {
var xml = GXml.parse(data);
//var markers = xml.documentElement.getElementsByTagName("marker");
//for (var i = 0; i < markers.length; i++) {
//var address = new GLatLng(parseFloat(markers[i].getAttribute("location")));
//var latlong = address.split(",");
//var latlongtomap = new GLatLng(parseFloat(latlong[0]), parseFloat(latlong[1]));
var latlongtomap = new GLatLng(51.477711,-3.176555);
var marker = createMarker(latlongtomap);
map.addOverlay(marker);
// }
});
}
}
如果我跑這一點,將獲得緯度和長COORDS並創建一個標記在地圖上爲我。但是,如果我試圖從我的PHP腳本獲得了 「位置」 選項卡(使用全部註釋掉的代碼):
map.php
這<?php
mysql_connect("", "", "") or die(mysql_error());
mysql_select_db("") or die(mysql_error());
$query = "SELECT MAPADDRESS FROM report";
$result = mysql_query($query) or die(mysql_error());
$doc = new DomDocument('1.0');
$node = $doc->createElement("markers");
$parnode = $doc->appendChild($node);
header("Content-type: text/xml");
while($row = mysql_fetch_array($result)){
$node = $doc->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("location", $row['MAPADDRESS']);
}
print $doc->saveXML();
?>
結果是:
<markers>
<marker location="51.477711,-3.176555"/>
<marker location="51.472512,-3.187527"/>
<marker location="51.471057,-3.186263"/>
<marker location="51.473261,-3.192219"/>
</markers>
爲什麼代碼不能正確讀取這個php?
感謝您的幫助!
HEMM
只是注意,你使用Google Maps API第2版,但是這過時了,而早在明年可能會被關閉。 – 2012-03-21 22:43:36