gpt4 book ai didi

android - 测量Android应用程序中两个坐标之间的距离

转载 作者:行者123 更新时间:2023-11-29 18:13:40 24 4
gpt4 key购买 nike

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

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 定价基本上只影响网络 map :http://code.google.com/apis/maps/faq.html#usage_apis

Google Maps for Android API 仍然免费。

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

此外,您可能会发现它很方便:Geographical distance

关于android - 测量Android应用程序中两个坐标之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9349589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com