在Google Maps上创建商店定位器

时间:2019-07-15 02:12:49

标签: php xml maps

我练习做这个在Google地图网站上找到的示例。 我通过将mysql更改为mysqli来更新了代码,但是当我执行代码时,出现错误的空白页面: 此页面包含以下错误: 第1行第3列出现错误:xmlParsePI:没有目标名称下面是直到第一个错误为止的页面呈现。

这是代码:

<?php
require("phpsqlsearch_dbinfo.php");

// Get parameters from URL
if (isset($_GET['center_lat'])) { $center_lat = $_GET['center_lat']; }
if (isset($_GET['center_lng'])) { $center_lng = $_GET['center_lng']; }
if (isset($_GET['radius'])) { $radius = $_GET['radius']; }

// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);

// Opens a connection to a mySQL server
$connection = mysqli_connect("localhost", "root", "", "serge");
if($connection) 

// Set the active mySQL database
$db_selected = mysqli_select_db($connection, "serge" );
if (!$db_selected) {
  die ("Can\'t use db : " . mysqli_connect_error());
}

// 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($connection, $center_lat),
  mysqli_real_escape_string($connection, $center_lng),
  mysqli_real_escape_string($connection, $center_lat),
  mysqli_real_escape_string($connection, $radius));
$result = mysqli_query ($connection, $query);

if (!$result) {
  die("Invalid query: " . mysqli_connect_error());
}

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']);
}

echo $dom->saveXML();
?>

0 个答案:

没有答案