我製作了帶有API v3的Google Map,地址爲this tutorial。Google Map API v3 MySQL?
.php爲從DB拉動的結果,你可以看到here。
但與谷歌地圖搜索應用於回來了沒有結果,你可以看到here。
當搜索位置時.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();
?>
這就是XML被撲滅當我搜索休斯敦,得克薩斯州在25英里半徑。
<?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>
搜索框是否工作?當我點擊搜索按鈕時,它將我帶到海洋中央。 – Andrew
這就是問題,我不知道爲什麼它不從數據庫拉標記信息。 .php文件本身就是,但使用.php文件的.html不是。 – NathanD
從.php代碼返回的XML文檔的開頭處有一個空格字符。嘗試刪除該空間。如果你調試了'collection.html',你應該在第65行('var xml = parseXml(data)')中看到,由於錯誤,XML不能被解析:「第6行第1行出錯:允許XML聲明只在文檔開始處「 – Andrew