php 使用纬度和经度的 40 公里半径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8850336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:38:21  来源:igfitidea点击:

Radius of 40 kilometers using latitude and longitude

phpmysqlgoogle-maps

提问by DerVO

Possible Duplicate:
Radius of multiple latitude/longitude points
distance calculations in mysql queries
select within 20 kilometers based on latitude/longitude

可能的重复:mysql 查询
中多个纬度/经度点
距离计算的半径根据纬度/经度
选择 20 公里以内

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.

我有一个 MyISAM 表,数据存储在其中。数据包括谷歌地图的纬度和经度。我想要实现的是选择样本经纬度40公里范围内的所有对象。

Thanks!

谢谢!

回答by DerVO

I use this query to get all points within a $radiusaround $lat/$lng:

我使用此查询来获取$radius周围$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

6371 is the earth radius im km. And I have not invented it: http://code.google.com/intl/en/apis/maps/articles/phpsqlsearch.htmlhttps://developers.google.com/maps/articles/phpsqlsearch_v3#findnearsql(edit: URL changed)

6371 是地球半径 im km。我还没有发明它:http: //code.google.com/intl/en/apis/maps/articles/phpsqlsearch.htmlhttps://developers.google.com/maps/articles/phpsqlsearch_v3#findnearsql(编辑:网址已更改)