gpt4 book ai didi

php - 谷歌地图商店定位器

转载 作者:行者123 更新时间:2023-11-29 00:45:35 25 4
gpt4 key购买 nike

您好,我正在学习 Google 上的创建商店定位器教程,可以在此处找到。

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();

但是当我运行脚本时,我收到了错误消息

This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.

有人能看出我的代码有什么问题吗?

最佳答案

$dom您尝试为其创建元素的对象在“while”循环之前不存在。首先创建该 DOMDocument 对象并包含 <markers>该对象中的根节点。

关于php - 谷歌地图商店定位器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10643880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com