sql geolocation lat,lng

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql geolocation lat,lng相关的知识,希望对你有一定的参考价值。

SELECT name,
       location_lat,
       location_lng,
       distance
FROM
  (SELECT z.name,
          z.location_lat,
          z.location_lng,
          p.radius,
          p.distance_unit * DEGREES(ACOS(COS(RADIANS(p.latpoint)) * COS(RADIANS(z.location_lat)) * COS(RADIANS(p.longpoint - z.location_lng)) + SIN(RADIANS(p.latpoint)) * SIN(RADIANS(z.location_lat)))) AS distance
   FROM restaurants AS z
   JOIN
     (SELECT 29.0907269 AS latpoint,
             -111.0281571 AS longpoint,
             50.0 AS radius,
             111.045 AS distance_unit) AS p ON 1=1
   WHERE
      z.location_lat BETWEEN p.latpoint - (p.radius / p.distance_unit) AND
      p.latpoint + (p.radius / p.distance_unit) AND
      z.location_lng BETWEEN p.longpoint - (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint)))) AND p.longpoint + (p.radius / (p.distance_unit * COS(RADIANS(p.latpoint))))) AS d
WHERE distance <= radius
ORDER BY distance LIMIT 15

以上是关于sql geolocation lat,lng的主要内容,如果未能解决你的问题,请参考以下文章

如何通过 SQL 连接选择使用 lat/lng 半径

如何将地理位置 lat lng 从函数传递到 React 中另一个函数的“ll”属性?

如果 lat/lng 为空,要在 lat/lng 数据库字段中添加啥?

Geofire - 未找到位置

SQL

Geonear 不工作 - mongodb?