【问题标题】:Measure distance between two coordinates in an android app在android应用程序中测量两个坐标之间的距离
【发布时间】:2012-02-19 13:30:45
【问题描述】:

我正在尝试测量两个坐标之间的距离,我已经实现了半正弦函数,就像这样:

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; 
}
}

代码工作正常并输出一些东西。但是当我使用半正弦公式时,代码只是测量天际线的距离,而不是道路,如果你知道我的意思的话。有没有像谷歌地图那样测量距离的方法?在不使用谷歌地图 API 的情况下,谷歌会在一天内调用 2500 次 API 后突然收取现金……

【问题讨论】:

标签: android haversine


【解决方案1】:

Google Maps API 定价基本上只影响 web 地图:http://code.google.com/apis/maps/faq.html#usage_apis

Google Maps for Android API 仍然免费。

OTOH,Android 版 Google 地图中没有路线或导航功能,因此无法使用此 API 计算路线距离。

另外,您可能会觉得这很方便:Geographical distance

【讨论】:

    【解决方案2】:

    您应该试试Bing Maps Android SDK。他们没有明确的使用配额。

    【讨论】:

      【解决方案3】:

      Bing 地图确实有使用配额,但这不适用于移动应用。必应地图绝对值得研究。您可以通过以下两种方式之一在 Android 上使用 Bing 地图。首先是使用Bing Maps Android SDK:http://bingmapsandroidsdk.codeplex.com/ 第二种是通过PhoneGap使用Bing Maps V7 AJAX控件。

      【讨论】:

        猜你喜欢
        • 2012-04-20
        • 1970-01-01
        • 2010-11-23
        • 2021-09-28
        • 2012-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多