mysql 计算经纬度范围内的数据

利用谷歌方案

The SQL statement that will find the closest 20 locations that are within a radius of 30 miles to the 78.3232, 65.3234 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude, and then asks for only rows where the distance value is less than 30 miles, orders the whole query by distance, and limits it to 20 results. To search by kilometers instead of miles, replace 3959 with 6371.

示例:(谷歌)

SELECT
  id, (
    3959 * acos (
      cos ( radians(78.3232) )
      * cos( radians( lat ) )
      * cos( radians( lng ) - radians(65.3234) )
      + sin ( radians(78.3232) )
      * sin( radians( lat ) )
    )
  ) AS distance
FROM markers
HAVING distance < 30
ORDER BY distance
LIMIT 0 , 20;

以上是谷歌说明,下面是用谷歌翻译的哈

根据以上说明,有以下应用实例

其中

3959是地球半径的英里,6371是地球半径的千米,LATITUDE是数据库字段的经度,LONGITUDE是数据库的纬度 ,18.7777是查找的经度,55.3774是查找的纬度即是有(18.7777,55.3774)这个位置点 搜索附近3.7KM的位置数据

SELECT
  id, (
    3959 * acos (
      cos ( radians(18.7777) )
      * cos( radians( LATITUDE) )
      * cos( radians( LONGITUDE) - radians(55.3774) )
      + sin ( radians(18.7777) )
      * sin( radians( LATITUDE) )
    )
  ) AS distance
FROM markers
HAVING distance < 3700
ORDER BY distance
LIMIT 0 , 20;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值