【问题标题】:Latitude and longitude distances separating the haversine method分离haversine方法的纬度和经度距离
【发布时间】:2015-06-22 19:42:44
【问题描述】:

有谁知道在两个谷歌标记之间可以找到单独的纬度和经度距离吗?我可以使用 hasrsine 方法获得总距离,例如: Find distance between two points on map using Google Map API V2

请问如何获取每个值?

谢谢

弗兰克

【问题讨论】:

  • 不就是像Math.abs(loc1.getLatitude() - loc2.getLatitude()) 这样loc1loc2 是你的位置吗?

标签: android google-maps


【解决方案1】:

Marker 类有一个Position 属性,所以

double latitudeDifferenceInDegrees = marker1.getPosition().latitude - marker2.getPosition().latitude;
double longitudeDifferenceInDegrees = marker1.getPosition().longitude - marker2.getPosition().longitude;

您可以将纬度差转换为以米为单位的距离 - 每度等于110.574 kilometers

double latitudeDifferenceInMeters = latitudeDifferenceInDegrees * 110574;

你不能对经度做同样的事情。在赤道上,经度约为 111 公里,但在两极附近,则要少得多。如果您只是在短距离内使用它,我会选择

double longitudeDifferenceInMeters = longitudeDifferenceInDegrees * 111320 * Math.cos((marker1.getPosition().latitude + marker2.getPosition().latitude) / 2);

请注意,如果第一个标记位于第二个标记的南部或西部,则两者都可以给出负值。如果您只对正值感兴趣,请申请Math.abs()

【讨论】:

  • 感谢 Glorfindel - 对于像我这样的新手来说,这看起来既好又容易。让她试一试
  • to Giorfinei:经度是水平的(X 轴),纬度是垂直的(Y 轴),是远离赤道的不同纬度。这种差异是由于墨卡托校正造成的,并且是因为您看到的是方形世界而不是矩形世界。您可以在“比例因子”en.wikipedia.org/wiki/Mercator_projection 找到更多详细信息
  • @NDorigatti 不,这根本不是真的。这与墨卡托无关 - 我使用的公式(以及 OP 提到的半正弦公式)来自spherical geometry。它们存在一个(相当小的)不准确性,因为地球不是球体而是椭球体。
  • 也许Lambert projection 会让你相信两极附近的经度更小(以米为单位)...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-26
  • 2012-02-10
相关资源
最近更新 更多