Google Maps Geocoder从MySQL数据库中查找附近的地方 [英] Google Maps geocoder to find nearby places from MySQL database

查看:139
本文介绍了Google Maps Geocoder从MySQL数据库中查找附近的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,该网站使用数据库提供的地址将位置存储在MySQL数据库和GeoCode中.

I have a website where I store locations in a MySQL database and GeoCode using the address provided by the database.

现在我想添加一个功能,该功能可以找到最接近指定点的地方,例如他们现在站立或输入的位置.我正在使用JavaScript和jQuery对地址解析器和Google地图进行编码,然后使用PHP从数据库中获取结果.

Now I want to add a feature which will find the closest places to the specified point e.g. the location they are standing now or typing. I'm coding the geocoder and google maps in JavaScript and jQuery and I get the results using PHP to fetch from the database.

我阅读了viewport的内容,但是我无法弄清楚它在我需要显示自己的数据库位置而不是Google位置的情况下如何工作.

I read about the viewport but I can't figure out how it would work in my situation where I need to show my own database locations and not Google's.

有人可以帮忙吗?如果您有这样的例子,那就太棒了.

Can anybody help? And it would be awesome if you have some kind of example.

推荐答案

半径搜索:

select *,
    acos(cos(centerLat * (PI()/180)) *
     cos(centerLon * (PI()/180)) *
     cos(lat * (PI()/180)) *
     cos(lon * (PI()/180))
     +
     cos(centerLat * (PI()/180)) *
     sin(centerLon * (PI()/180)) *
     cos(lat * (PI()/180)) *
     sin(lon * (PI()/180))
     +
     sin(centerLat * (PI()/180)) *
     sin(lat * (PI()/180))
    ) * 3959 as Dist
from TABLE_NAME
having Dist < radius
order by Dist

3959是以英里为单位的地球半径.将此值替换为 以KM为单位的半径(或任何单位),以在同一单位上获得结果. centerLat centerLon 是搜索的中心(您的 输入),而lat和lon是表格中的字段.

3959 is the Earth radius in Miles. Replace this value with radius in KM, or any unit, to get results on the same unit. centerLat and centerLon are the center of the search (your input), while lat and lon are fields in the table.

这篇关于Google Maps Geocoder从MySQL数据库中查找附近的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆