1

我正在尝试测量两个坐标之间的距离,我已经实现了 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; 
}
}

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

4

3 回答 3

2

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

Google Maps for Android API 仍然是免费的。

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

此外,您可能会发现这很方便:地理距离

于 2012-02-19T13:57:41.347 回答
1

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

于 2012-02-19T13:41:04.660 回答
0

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

于 2012-03-02T16:22:31.890 回答