我正在尝试使用 R 计算地球上两点之间的距离。
library(geosphere)
library(oce)
geodDist(StoreLocations$latitude[c(26)], StoreLocations$longitude[c(26)],
CustomerLocations$latitude[c(5)], CustomerLocations$longitude[c(5)])
在谷歌地图中放入纬度/经度(测量距离功能)。我得到总距离:1.88 公里(1.17 英里),但这不是我使用上面的代码得到的。我正在努力寻找可以帮助我解决这个问题的人。
Store 51.68108210 -0.09732268
Customer 51.66665932 -0.08300349
最佳答案
通过阅读 geosphere
文档,您似乎颠倒了参数顺序。 geoDist
(或最新版本包中的 distGeo
,发布于 2016 年 6 月 15 日)首先需要经度,然后是纬度。你似乎首先有自由度。
df <- data.frame(long = c(-0.09732268, -0.08300349), lat = c(51.68108210, 51.66665932))
long lat
1 -0.09732268 51.68108
2 -0.08300349 51.66666
distGeo(df[1, ], df[2, ])
1885.795 (1.88 km)
您还应该检查以确保您使用的是最新版本的软件包。
关于r - R中地球上两个地方之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39148984/