我正在关注如何将Google地图用作商店定位器here的教程,但是,我的网页正在输出XML错误:
错误是什么意思?我将如何解决它?
我在.php文件中声明了GLOBALS,该文件包含以下信息。我的require()
$GLOBALS['SRVR'] ='myServer';
$GLOBALS['USER'] ='myUID';
$GLOBALS['PASS'] ='myPASSWORD';
然后我将教程中演示的代码放在一个函数中,然后调用该函数。我还将mysql
转换为mysqli
。
我还创建了名为markers
的表,就像在教程中一样。
require("indexhead.php");
function MaptheStore() //I plan to add an argument later to populate stores
{
// 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);
// Set the active mySQL database
$db_selected = mysqli_select_db($GLOBALS['con'], 'myDB');
if (!$db_selected) {
die (mysqli_error($db_selected));
}
// 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 myDB.markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysqli_real_escape_string($GLOBALS['con'],$center_lat),
mysqli_real_escape_string($GLOBALS['con'],$center_lng),
mysqli_real_escape_string($GLOBALS['con'],$center_lat),
mysqli_real_escape_string($GLOBALS['con'],$radius));
$result = mysqli_query($GLOBALS['con'],$query);
if (!$result) {
die("Invalid query: " . mysqli_error($result));
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysqli_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']);
}
return $dom->saveXML();
}
echo MapTheStore();
最后,我粘贴它来模拟$ _GET [](?lat=37&lng=-122&radius=25
),以测试教程中的页面。
我将代码转换为mysqli会导致错误吗?我该如何解决?究竟是什么导致错误?
编辑:这是我markers
的表结构
以下是它的内容......
编辑:网页的页面源有这个输出,基本上只有我的标题: