簡體   English   中英

測量Android應用程序中兩個坐標之間的距離

[英]Measure distance between two coordinates in an android app

我試圖測量兩個坐標之間的距離,我已經實現了hasrsine函數,就像這樣:

package Services;

public class Route {

private double latitude1;
private double longitude1; 
private double latitude2;
private double longitude2; 


public Route(double latitude1, double longitude1, double latitude2, double longitude2) {

    this.latitude1 = latitude1;
    this.longitude1 = longitude1;
    this.latitude2 = latitude2;
    this.longitude2 = longitude2;
}

public double measureDistance() {

     double earthRadius = 3958.75;
     double dLat = Math.toRadians(latitude2-latitude1);
     double dLng = Math.toRadians(longitude2-longitude1);
     double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
                   Math.cos(Math.toRadians(latitude1)) * Math.cos(Math.toRadians(latitude2)) *
                   Math.sin(dLng/2) * Math.sin(dLng/2);

     double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
     double dist = earthRadius * c;

    return dist; 
}
}

代碼工作正常,輸出一些東西。 但是當我使用haversine公式時,代碼只測量天際線中的距離,如果您知道我的意思,則不是道路。 有沒有可能像谷歌地圖那樣測量距離? 沒有使用谷歌地圖API,蘇格麗谷歌在一天之內2500次API調用后需要現金。

Google Maps API的定價基本上只影響網絡地圖: http : //code.google.com/apis/maps/faq.html#usage_apis

Google Maps for Android API仍然免費。

OTOH,Google Maps for Android中沒有路由或導航功能,因此無法使用此API計算路線距離。

此外,您可能會發現這個方便: 地理距離

您應該嘗試使用Bing Maps Android SDK 他們沒有明確的使用配額。

必應地圖確實有使用配額,但這不適用於移動應用程序。 Bing Maps絕對值得研究。 您可以通過以下兩種方式之一使用Bing Maps with Android。 第一種是使用Bing Maps Android SDK: http//bingmapsandroidsdk.codeplex.com/第二種是使用Bing Maps V7 AJAX控件和PhoneGap。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM