嗨,我正在通过谷歌上的创建商店定位器教程,可以在这里找到。
https://developers.google.com/maps/articles/phpsqlsearch_v3#findnearsql
我的代码是
// Select all 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",
mysql_real_escape_string("37.414832"),
mysql_real_escape_string("-122.024857"),
mysql_real_escape_string("37.414832"),
mysql_real_escape_string("10"));
$result = mysql_query($sql);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
else
{
echo 'success';
}
// Start XML file, echo parent node
echo "<markers>\n";
// Iterate through the rows, printing 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']);
}
// End XML file
echo "</markers>\n";
echo $dom->saveXML();
但是,当我运行脚本时,我收到错误消息
此页面包含以下错误:
第 1 行第 1 列的错误:文档为空
下面是页面的呈现直到第一个错误。
有人能看出我的代码有什么问题吗?