MySQL内距离查询 [英] Mysql within distance query

查看:128
本文介绍了MySQL内距离查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选项

$lat = '25.7742658';
$lng = '-80.1936589';
$miles = 30;

查询

SELECT *, 
   ( 3959 * acos( cos( radians($lat) ) 
   * cos( radians( lat ) ) 
   * cos( radians( lng ) - radians($lng) ) 
   + sin( radians($lat) ) 
   * sin( radians( lat ) ) ) ) AS distance 
FROM locations 
HAVING distance < $miles 
ORDER BY distance 
LIMIT 0, 20

我有一个包含4列的数据库表:

I have a database table with 4 columns:

  • 唯一ID
  • 城市名称
  • 纬度(纬度)
  • 经度(lng)

我在顶部使用查询返回距指定坐标距离指定英里数内的位置.它似乎可行,但我不确定它的准确性如何.我很想知道查询是否很好,或者您是否有更好的解决方案.

I'm using the query on top to return locations that are within a specified number of miles from the specified coordinates. It seems to work but I'm not sure how accurate it is. I'm curios to know whether the query is good or if you have a better solution.

推荐答案

看起来像是正确的大圆距查询.

that looks like the correct great circle distance query.

您对wrt的准确性有什么担心?

what are you concerned with wrt accuracy?

这篇关于MySQL内距离查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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