使用 MySQL 计算结果中的所有纬度和经度距离

Calculate all latitude and longitude distance in result using MySQL

这是我当前在两个纬度和经度之间计算的查询,但是我如何使用这个或类似的公式来计算结果中的所有纬度和经度?

SELECT ROUND(6353 * 2 * ASIN(SQRT( POWER(SIN((a.GPSLat -
      abs(b.GPSLat)) * pi()/180 / 2),2) + COS(a.GPSLat * pi()/180 ) * COS(
      abs(b.GPSLat) *  pi()/180) * POWER(SIN((a.GPSLon - b.GPSLon) *  
      pi()/180 / 2), 2) )), 2) as "Total(KM)"
from table1 a
      inner join table1 b on a.ID = 70 and b.ID = 71;

这是我的数据库经纬度示例

结果按id70和id71计数

不是 100% 清楚你的意思,但你是说你想计算所有坐标对的距离吗?如果是这样,您正在尝试进行交叉连接:

SELECT a.id, b.id , ...(your formula) from 
  (select id from Table1 
      [some join with filtered table]
       where [some predicate] ) a 
  CROSS JOIN 
  ( ... similar query to above to filter your right hand set... )b 

抱歉 iPad 现在输入所有内容令人恼火。

不要对交叉连接应用任何 on 或 where,因为这会将其变成内部连接。

这将为您提供所有对之间的距离。

查看一些优化方法: Cross Join without duplicate combinations