我使用的創建商店定位器提供了https://developers.google.com/maps/articles/phpsqlsearch_v3提供的PHP,MySQL和Google Maps示例。Google Map API PHP示例
我遇到了XML文檔寫入的問題。我可以從Querious(數據庫應用程序)運行查詢成功,但是當試圖運行提供的腳本(我將其修改爲mysqli)時,事情並不適合我。我沒有得到任何回報。數據庫的設置與示例中提供的一樣。下面是修改的PHP,我使用:
PHP
<?php
require_once('../includes/connection.php');
require_once('../includes/function.php');
// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Search the rows in the markers table
$query = sprintf("SELECT address, name, lat, lng, (3959 * acos(cos(radians('%s')) * cos(radians(lat)) * cos(radians(lng) - radians('%s')) + sin(radians('%s')) * sin(radians(lat)))) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysqli_real_escape_string($mysqli , $center_lat),
mysqli_real_escape_string($mysqli , $center_lng),
mysqli_real_escape_string($mysqli , $center_lat),
mysqli_real_escape_string($mysqli , $radius));
$result = mysqli_query($mysqli, $query);
$result = mysqli_query($mysqli, $query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("distance", $row['distance']);
}
echo $dom->saveXML()
?>
我知道,無論我的連接是成功的,其功能是免費的錯誤。感謝您對此的任何見解。
先生,我們有一個winna!謝謝你,對我來說完全忽略! – Bungdaddy