Php 附近地点脚本帮助
我正在阅读 http://code.google.com/apis/maps/articles/ phpsqlsearch.html 获取 SQL/数学。我写了一些 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';
}
?>
数据库结构和数据与Google代码文章中的相同。
这就是我的 PHP 脚本。有什么问题吗?我认为这可能是 SQL 问题。不太确定。这篇文章是 2008 年 1 月发布的,所以内容可能发生了变化?
I was reading http://code.google.com/apis/maps/articles/phpsqlsearch.html to get the SQL/Math. I wrote a little php script but i get no results.
<?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';
}
?>
Database structure and data is the same as in the Google code article.
Thats my Php script. Whats wrong with it? I am thinking it might be a SQL issue. Not really sure. This post is from Jan 2008, So maybe stuff changed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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
http://www.geonames.org/export/
Use geonames.org to get what you want. that is finding near by places.
This server was never down. I have been checking this for a long time unlike http://webservicex.net.
You can use it in javascript as well as in PHP.
http://booking.com is using a servies like this to display hotels, airports, etc near by a hotel.
I have been using this service for one of my projects.
geonames provides a database dump and they update this periodically i hope.
You can find more information in their site.
http://www.geonames.org/export/web-services.html
http://forum.geonames.org/gforum/posts/list/499.page
?>
?>