我使用本教程使用 API v3 制作了 Google 地图。
如您在此处所见,.php 正在从数据库中提取结果。
但是,当应用到谷歌地图搜索时,没有结果,如您在此处看到的。
.html 文件在搜索位置时不会从数据库中提取标记。我已经检查了代码 100 次,并在网上寻找我哪里出错的答案。如果有人可以为这个问题带来一些启示,将不胜感激。
这是.php
<?php
require("phpsqlsearch_dbinfo.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);
// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ("Can\'t use db : " . mysql_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",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// 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();
?>
这就是我在 25 英里半径范围内搜索德克萨斯州休斯顿时 XML 输出的内容。
<?xml version="1.0"?>
<markers><marker name="US Healthworks" address="9200 Hempstead, Houston, TX" lat="29.794104" lng="-95.449448" distance="5.34265857252369"/><marker name="Concentra Urgent Care" address="1000 N Post Oak, Houston, TX" lat="29.785303" lng="-95.456039" distance="5.47896700195167"/><marker name="US Healthworks" address="1414 S. Loop West, Houston, TX" lat="29.680426" lng="-95.399132" distance="5.79347704035615"/><marker name="Concentra Urgent Care" address="8799 North Loop E., Houston, TX" lat="29.797531" lng="-95.273872" distance="6.28265385500935"/><marker name="Doctor's Clinic Houston" address="6535 Southwest Freeway, Houston, TX" lat="29.717321" lng="-95.497299" distance="8.22610378379106"/><marker name="Northshore Occupational Medica" address="1140 Westmont Ste. 505, Houston, TX" lat="29.771984" lng="-95.195290" distance="10.4743938030692"/><marker name="US Healthworks" address="16630 Imperial, Houston, TX" lat="29.941263" lng="-95.396309" distance="12.615115596934"/><marker name="NOVA" address="6630 Roxburgh Drive, Houston, TX" lat="29.866304" lng="-95.555901" distance="13.371308778454"/><marker name="Fishbone Safety" address="208 X Street, Deer Park, TX" lat="29.694548" lng="-95.122627" distance="15.4859102039821"/><marker name="US Healthworks" address="17410 N.W. Freeway, Houston, TX" lat="29.888929" lng="-95.582146" distance="15.5495324355371"/><marker name="US Healthworks" address="10521 Corporate, Stafford, TX" lat="29.632973" lng="-95.596115" distance="16.2008784561048"/><marker name="Occupational Healthcare" address="610 S. Main Street, Highlands, TX" lat="29.808447" lng="-95.056885" distance="19.0351671183224"/><marker name="Medical Plaza Mobile Surveillance" address="10910 Spencer, La Porte, TX" lat="29.632973" lng="-95.062325" distance="20.4197847454651"/><marker name="US Healthworks" address="1309 West Fairmont Pkwy, LaPorte, TX" lat="29.651571" lng="-95.030998" distance="21.6516577038734"/></markers>