开发者社区 问答 正文

使用SQL查询查找最接近的纬度/经度

我有经度和纬度,我想从数据库中提取记录,该记录具有最接近的经度和纬度距离,如果该距离长于指定距离,则不要检索它。

表结构:

id latitude longitude place name city country state zip sealevel

展开
收起
保持可爱mmm 2020-05-10 20:53:51 628 分享 版权
1 条回答
写回答
取消 提交回答
  • SELECT latitude, longitude, SQRT( POW(69.1 * (latitude - [startlat]), 2) + POW(69.1 * ([startlng] - longitude) * COS(latitude / 57.3), 2)) AS distance FROM TableName HAVING distance < 25 ORDER BY distance; 其中[starlat]和[startlng]是开始测量距离的位置

    2020-05-10 20:53:58
    赞同 展开评论
问答分类:
问答地址: