You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MYSQL如何判断给定坐标点是否在已存储的经纬度边界区域内

问题排查
  • 字段名不匹配:你现有查询使用的south_lat、north_lat、south_lng、north_lng并非表中实际存在的字段,你的区域表存储边界坐标的字段为north_east_lat(区域东北角纬度)、south_west_lat(区域西南角纬度)、north_east_long(区域东北角经度)、south_west_long(区域西南角经度)。
  • 坐标判断逻辑需符合经纬度特性:常规WGS84等坐标系下,纬度数值越高代表位置越靠北,因此区域东北角的纬度必然大于西南角纬度;东经范围内经度数值越高代表位置越靠东,区域东北角经度大于西南角经度。
通用场景查询语句(适用于不跨180度经线的区域)
SELECT * FROM test 
WHERE 
  36.206006 BETWEEN south_west_lat AND north_east_lat
  AND 43.995311 BETWEEN south_west_long AND north_east_long
兼容跨180度经线场景的查询语句

如果你的业务涉及跨国际日期变更线的区域存储,可使用以下逻辑兼容:

SELECT * FROM test 
WHERE 
  36.206006 BETWEEN south_west_lat AND north_east_lat
  AND (
    (south_west_long <= north_east_long AND 43.995311 BETWEEN south_west_long AND north_east_long)
    OR (south_west_long > north_east_long AND (43.995311 >= south_west_long OR 43.995311 <= north_east_long))
  )

内容的提问来源于stack exchange,提问作者Mohammed Riyadh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 20:18:05