使用经纬度40公里的半径 [英] Radius of 40 kilometers using latitude and longitude
问题描述
可能存在重复:
多个纬度/经度点的半径
在MySQL查询中的距离计算
根据纬度/经度在20公里内选择
Possible Duplicate:
Radius of multiple latitude/longitude points
distance calculations in mysql queries
select within 20 kilometers based on latitude/longitude
我有一个MyISAM表格,数据存储在其中。数据包括Google Maps的纬度和经度。我试图达到的目标是选取样本纬度和经度40公里范围内的所有物体。
I have a MyISAM table, which the data is stored in. The data includes latitude and longitude for Google Maps. What I am trying to achieve is to select all objects within the radius of 40 kilometers of the sample latitude and longitude.
谢谢!
推荐答案
我使用这个查询来得到 $ lat周围的
$ radius
中的所有点 / $ lng
:
I use this query to get all points within a $radius
around $lat
/$lng
:
SELECT
*,
( 6371 * acos( cos( radians({$lat}) ) * cos( radians( `lat` ) ) * cos( radians( `lng` ) - radians({$lng}) ) + sin( radians({$lat}) ) * sin( radians( `lat` ) ) ) ) AS distance
FROM `positions`
HAVING distance <= {$radius}
ORDER BY distance ASC
<63>是地球半径im km。我还没有发明它:
http://代码。 google.com/intl/zh_CN/apis/maps/articles/phpsqlsearch.html
https://developers.google.com/maps/articles/phpsqlsearch_v3#findnearsql (编辑:URL已更改)
6371 is the earth radius im km. And I have not invented it:
http://code.google.com/intl/en/apis/maps/articles/phpsqlsearch.html
https://developers.google.com/maps/articles/phpsqlsearch_v3#findnearsql (edit: URL changed)
这篇关于使用经纬度40公里的半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!