【发布时间】:2013-12-23 11:47:54
【问题描述】:
我正在尝试编写一个在 android 中使用 Google Maps V2 API 的简单应用程序。 在计时器中,我正在从 googleMap mylocation 函数中读取 lat long 值。
altitude = googleMap.getMyLocation().getAltitude();
latitude = googleMap.getMyLocation().getLatitude();
longitude = googleMap.getMyLocation().getLongitude();
我使用addPolyline() 方法绘制了经纬度。
我面临的问题是在前台使用此应用程序在路上行走时,我一直在直线行走,但情节在附近的建筑物中。我确保 2 lat,longs 的距离为 10m。
我用公式,
public double calcDistance(double lat1, double lng1, double lat2,
double lng2) {
int r = 6371; // average radius of the earth in km
double dLat = Math.toRadians(lat2 - lat1);
double dLon = Math.toRadians(lng2 - lng1);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ Math.cos(Math.toRadians(lat1))
* Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2)
* Math.sin(dLon / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d = r * c;
return d;
}
问题 - 如何获得一条直线,如何获得准确性或余量或误差,以便在路上行走时我不会进入建筑物
【问题讨论】:
标签: android google-maps