【问题标题】:The distance Calculation from two places两地距离计算
【发布时间】:2011-04-26 21:55:15
【问题描述】:

我有两个地方的纬度和经度。我可以在android中计算它们之间的距离吗?

【问题讨论】:

标签: android


【解决方案1】:

您正在寻找的是 hasrsine 公式,它使用它们的纬度和经度给出球体上两点之间的距离。

Haversine 公式:

R = 地球半径(平均半径 = 6371km)
Δlat = lat2 - lat1
Δlong = long2 − long1
a = sin²(Δlat/2) + cos(lat1)*cos(lat2)*sin²(Δlong/2)
c = 2*atan2(√a, √(1−a))
d = R*c

在 JavaScript 中:

var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad(); 
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
        Math.sin(dLon/2) * Math.sin(dLon/2); 
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
var d = R * c;

http://www.movable-type.co.uk/scripts/latlong.html

【讨论】:

    【解决方案2】:
    【解决方案3】:

    这个 API 就是你想要的:

    http://developer.android.com/reference/android/location/Location.html#distanceBetween(double,%20double,%20double,%20double,%20float[])

    (注意:它是静态的...不需要 Location 对象实例)

    【讨论】:

      猜你喜欢
      • 2011-09-21
      • 1970-01-01
      • 1970-01-01
      • 2012-12-25
      • 2023-03-23
      • 2011-12-24
      • 2018-10-05
      • 2011-09-26
      相关资源
      最近更新 更多