使用经度和纬度获取最近的位置
问题描述:
我有一张桌子hotspots
id name date
1 foo 2011-06-15 15:10:34
2 bar 2011-07-02 16:45:18
和一张桌子locations
hotspotid zipcode latitude longitude
1 90001 xxxxx xxxxx
2 45802 xxxxx xxxxx
如何使用SQL查询列出附近具有英里数限制的特定纬度和经度的热点?
How can i list the hotspots nearby to a specific latitude and longitude with miles limit using an SQL query?
P.S.我想要一个纯SQL解决方案,但是如果需要的话php是可以的.
P.S. i'd like a pure SQL solution but php is ok if it's needed.
谢谢
答
首先,最好使用纬度和经度为每个热点确定一个地理位置.您可以使用 Google地理编码API 浏览每条记录并存储经度/纬度.
First you need a geographic location for each hotspot ideally using latitude and longitude. You can use the Google Geocoding API to go through each record and store lat/long.
然后,您可以将附近的热点与此SQL查询进行匹配并按距离排序.
Then you can match nearby hotspots with this SQL query and order by distance.
希望有帮助.