目前在home.php上使用downloadURL()來下載xml.php文件。從數據庫創建xml文檔以在地圖上顯示標記。工作得很好,但現在我收到geoCode/lat/long的錯誤。有什麼建議? FireFox錯誤:未定義偏移[0]通過結果。在谷歌地圖中設置經度和緯度 - 未定義的結果
<?php
include 'connect.php';
if(isset($_SESSION['user_name']))
{
header('Location: home.php');
}
$query = "SELECT `acc_id`,`acc_name`,`acc_address`,acc_zip FROM `account_acc` ";
$result = mysqli_query($connection,$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 = mysqli_fetch_array($result))
{
$node = $doc->createElement("marker");
$newnode = $parnode->appendChild($node);
$address = $row['acc_zip'];
$prepAddr = str_replace(' ','+',$address);
$geocode=file_get_contents('https://maps.google.com/maps/api/geocode/json?key=API&address='.$prepAddr);
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
$newnode->setAttribute("name", $row['acc_name']);
$newnode->setAttribute("accid", $row['acc_id']);
$newnode->setAttribute("address", $row['acc_address']);
$newnode->setAttribute("zip", $row['acc_zip']);
$newnode->setAttribute("lat", $lat);
$newnode->setAttribute("long", $long);
}
print $doc->saveXML();
?>