我正在使用https://developers.google.com/maps/articles/phpsqlsearch_v3提供的带有 PHP、MySQL 和 Google 地图示例的创建商店定位器。
我在编写 XML 文档时遇到问题。我可以从 Querious(DB 应用程序)成功运行查询,但是当尝试运行我修改为 mysqli 的提供的脚本时,事情对我不利。我什么也没得到。DB 按照示例中提供的方式设置。这是我使用的修改后的 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()
?>
我知道我的连接都是成功的,并且功能没有错误。感谢您对此的任何见解。