我想從ios(這是工作正常)得到輸出的經緯度和座標,發送到PHP與MySQL查詢和有PHP發送一個xml文檔返回給ios(這一步不工作,因爲它沒有帶回該位置的mysql條目),然後解析它在iOS UItableview(這也工作得很好)。我試圖讓這與XML工作,因爲我已經得到了一個簡單的XML腳本已經在它上面運行。但可能是由於缺乏經驗的PHP錯誤,我無法獲得這個PHP腳本的工作!我在我的PHP腳本中做錯了什麼?謝謝!哦,而且,在mysql中的數據類別由「lon」和「lat」和「name」(爲附近的朋友或家人的名字)組成!而如果有人想知道,這是一個較早的腳本的演進版本(這也產生了相同的結果):php query for iOS latitude and longitude not searching for nearby mysql lat and lon with a xml outputphp是不匹配ios lon和拉特與mysql的lon和lat正確
<?php
define('LATMILES', 1/69);
define('LONMILES', 1/53);
if (isset($_GET['lat'])) { $lat = (float)$_GET['lat']; } //Recieve ios input from: NSString *urlString = [NSString stringWithFormat:@"http://www.mysite.com/loc.php?lat=%g&lon=%g&radius=100&q=%@", latitude, longitude, searchBar.text?searchBar.text:@""];
if (isset($_GET['lon'])) { $lon = (float)$_GET['lon']; } //Recieve ios input from: NSString *urlString = [NSString stringWithFormat:@"http://www.mysite.com/loc.php?lat=%g&lon=%g&radius=100&q=%@", latitude, longitude, searchBar.text?searchBar.text:@""];
if (isset($_GET['radius'])) { $radius = (float)$_GET['radius']; } //Recieve ios input from: NSString *urlString = [NSString stringWithFormat:@"http://www.mysite.com/loc.php?lat=%g&lon=%g&radius=100&q=%@", latitude, longitude, searchBar.text?searchBar.text:@""];
$minlat = $lat - ($radius * LATMILES);
$minlon = $lon - ($radius * LONMILES);
$maxlat = $lat + ($radius * LATMILES);
$maxlon = $lon + ($radius * LONMILES);
$dbh = new PDO('(censored private information');
$sql = 'SELECT lat, lon, name FROM locations WHERE lat >= ? AND lat <= ? AND lon >= ? AND lon <= ?';
$params = array($minlat, $maxlat, $minlon, $maxlon);
if (isset($_GET['q'])) {
$sql .= " AND name LIKE ?";
$params []= '%'.$_GET['q'].'%';
}
$q = $dbh->prepare($sql);
$q->execute($params);
$doc = new DOMDocument();
$r = $doc->createElement("locations");
$doc->appendChild($r);
foreach ($q->fetchAll() as $row) {
$dlat = ((float)$row['lat'] - $lat)/LATMILES;
$dlon = ((float)$row['lon'] - $lon)/LONMILES;
$d = sqrt(($dlat * $dlat) + ($dlon * $dlon));
if ($d <= $radius) {
$e = $doc->createElement("location");
$e->setAttribute('lat', $row['lat']);
$e->setAttribute('lon', $row['lon']);
$e->setAttribute('name', $row['name']);
$r->appendChild($e);
}
}
print $doc->saveXML();
?>
嗯......你看過我的問題嗎?這是一個腳本,由於腳本執行的變化需要重新發布...... – user1667601
系統不會讓我撤銷我的近距離投票。遊民。如果你想避免被標記,不要在你的問題中一遍又一遍地複製和粘貼相同的文本,並嘗試將代碼減少到相關的部分。否則,它看起來像是同樣的問題與膚淺的修改。遵循這些建議可能還會吸引更多的問題答案。 – Trott
我會記住這些的。另一個說明,你有任何建議來解決這個腳本?我應該在哪裏看? – user1667601