2

我正在阅读http://code.google.com/apis/maps/articles/phpsqlsearch.html以获取 SQL/Math。我写了一个小 php 脚本,但我没有得到任何结果。

    <?php
$db_host = "localhost";
$db_username = "root"; 
$db_pass = "";
$db_name = "places";

mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database");

$lat = "37";
$lon = "-122";
$radius = "25";
$sql = mysql_query("SELECT id, name, ( 3959 * acos( cos( radians('$lat') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('$lon') ) + sin( radians('$lat') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '$radius' ORDER BY distance LIMIT 0 , 20") or die("error");

$nearby_check = mysql_num_rows($sql); 
if ($nearby_check > 0)
{
    while($row = mysql_fetch_array($sql))
    {
        $name = $row["name"];
        echo $name . '<br />';
    }
}
else
{
    echo 'No Places found nearby';  
}
?>

数据库结构和数据与谷歌代码文章中的相同。

那是我的 PHP 脚本。它出什么问题了?我认为这可能是一个 SQL 问题。不太确定。这篇文章来自 2008 年 1 月,所以也许事情发生了变化?

4

2 回答 2

1

http://www.geonames.org/export/

使用 geonames.org 得到你想要的。那是在附近的地方找到。

该服务器从未停机。与http://webservicex.net不同,我已经检查了很长时间。

您可以在 javascript 和 PHP 中使用它。

http://booking.com正在使用这样的服务来显示酒店附近的酒店、机场等。

我一直在为我的一个项目使用这项服务。

geonames 提供了一个数据库转储,我希望他们会定期更新。

您可以在他们的网站上找到更多信息。

http://www.geonames.org/export/web-services.html

http://forum.geonames.org/gforum/posts/list/499.page

于 2010-12-18T22:56:16.647 回答
0
<?php
require_once('config.php'); 

$lat = "4.2709781";
$lng = "-120.2881378";
$radius = "10";

$req = $bdd ->prepare("SELECT id, name, lat, lng, ( 6371 * acos( cos( radians('$lat') ) * cos( radians( lat) ) * cos( radians( lng) - radians('$lng') ) + sin( radians('$lat') ) * sin( radians( lat) ) ) ) AS distance FROM markertable HAVING distance < '$radius' ORDER BY distance LIMIT 0 , 40");

$req->execute();

$datas = array();
$i=0;

while($tmpData = $req->fetch()) {
    $datas[$i]['id'] = utf8_encode($tmpData['id']);
    $datas[$i]['name'] = utf8_encode($tmpData['name']);
    $datas[$i]['lat'] = utf8_encode($tmpData['lat']);
    $datas[$i]['lng'] = utf8_encode($tmpData['lng']);
    $datas[$i]['distance'] = utf8_encode($tmpData['distance']);
    $i++;
}

$jsonOutPut = json_encode(array('markers'=>$datas));
echo $jsonOutPut;
$bdd = null;    

?>

于 2018-06-11T12:38:42.690 回答