我有一个地理编码条目的数据库。我需要确定哪两个条目距离总条目的子集最远。例如,我选择一个包含 10 个条目的列表,然后从该列表中确定哪两个位置代表该列表中的最大距离。
我不知道如何处理这个问题。我什至考虑过使用弧度,但似乎没有什么能满足要求。
仅供引用,这里是 LAMP 堆栈......
最佳答案
以下查询将计算所有点之间的距离并返回距离最大的两个点:
SELECT coor1.longitude as lon1,
coor1.latitude as lat1,
coor2.longitude as lon2,
coor2.latitude as lat2,
(ACOS(
COS(RADIANS(coor1.latitude)) *
COS(RADIANS(coor1.longitude)) *
COS(RADIANS(coor2.latitude)) *
COS(RADIANS(coor2.longitude)) +
COS(RADIANS(coor1.latitude)) *
SIN(RADIANS(coor1.longitude)) *
COS(RADIANS(coor2.latitude)) *
SIN(RADIANS(coor2.longitude)) +
SIN(RADIANS(coor1.latitude)) *
SIN(RADIANS(coor2.latitude))
) * 6378 --- Use 3963.1 for miles
)
AS DistanceKM
FROM coordinates coor1,
coordinates coor2
WHERE NOT (coor1.longitude = coor2.longitude AND coor1.latitude = coor2.latitude)
ORDER BY DistanceKM DESC
LIMIT 1; --- Only the biggest
现在我建议事先进行这些计算并将结果存储在单独的表中。
关于mysql - 列表中纬度/经度之间的最长距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1283016/