2013-02-02 88 views

回答

2

您可以使用Android SDK功能distanceBetween

計算兩個位置之間的近似距離(以米爲單位),以及可選的兩個位置之間的最短路徑的初始和最終方位。距離和方位使用WGS84橢球定義。

1

試試這個,你會得到距離

private String distance(double lati, double longi, double curlati1, 
     double curlongi1) { 

    double theta = longi - curlongi1; 
    double dist = Math.sin(deg2rad(lati)) * Math.sin(deg2rad(curlati1)) 
      + Math.cos(deg2rad(lati)) * Math.cos(deg2rad(curlati1)) 
      * Math.cos(deg2rad(theta)); 
    dist = Math.acos(dist); 
    dist = rad2deg(dist); 
    dist = dist * 60 * 1.1515; 

    dist = dist * 1.609344; 

    result = Double.toString(dist); 
    System.out.println("dist_result :" + result); 
    return (result); 
} 

/* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ 
/* :: This function converts decimal degrees to radians : */ 
/* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ 
private double deg2rad(double deg) { 
    return (deg * Math.PI/180.0); 
} 

/* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ 
/* :: This function converts radians to decimal degrees : */ 
/* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ 
private double rad2deg(double rad) { 
    return (rad * 180.0/Math.PI); 
} 
+0

其中單位這個距離是? –

相關問題