【发布时间】:2018-10-11 09:32:17
【问题描述】:
我想得到两个刚刚到来的纬度和经度之间的确切差异。为了实现这一点,我尝试了很多代码。喜欢:
GeodeticCalculator geoCalc = new GeodeticCalculator();
Ellipsoid reference = Ellipsoid.WGS84;
Double dbLat = Double.valueOf(latLong[0]);
Double dbLong = Double.valueOf(latLong[1]);
Toast.makeText(this, "" + dbLat + "," + dbLong, Toast.LENGTH_SHORT).show();
GlobalPosition pointA = new GlobalPosition(Double.valueOf(latLong[0]), Double.valueOf(latLong[1]), 0.0);
GlobalPosition userPos = new GlobalPosition(lat2, long2, 0.0);
distance = geoCalc.calculateGeodeticMeasurement(reference, userPos, pointA).getPointToPointDistance();
还有
public static double getDistance2(double lat1, double lon1, double lat2, double lon2) {
double theta = lon1 - lon2;
double dist = Math.sin(deg2rad(lat1))
* Math.sin(deg2rad(lat2))
+ Math.cos(deg2rad(lon1))
* Math.cos(deg2rad(lon2))
* Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
return (dist);
}
private static double deg2rad(double deg) {
return (deg * Math.PI / 180.0);
}
private static double rad2deg(double rad) {
return (rad * 180.0 / Math.PI);
}
和
public static Double getDistance1(double lat1, double lng1, double lat2, double lng2) {
double earthRadius = 6371000; //meters
double dLat = Math.toRadians(lat2 - lat1);
double dLng = 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(dLng / 2) * Math.sin(dLng / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
Double dist = (Double) (earthRadius * c);
return dist;
}
最后,
public static Double getDistance(Double lat1,Double long1,Double lat2,Double long2){
Location startPoint=new Location("locationA");
startPoint.setLatitude(lat1);
startPoint.setLongitude(long1);
Location endPoint=new Location("locationA");
endPoint.setLatitude(lat2);
endPoint.setLongitude(long2);
double distance=startPoint.distanceTo(endPoint);
return distance;
}
但是直到现在我都无法获得确切的位置。所以请帮我解决我的问题。
【问题讨论】:
-
定义
exact(1) 线性或 (2) 球形 -
哪个最好。
-
Ofcouse Spherical......因为在Linear中,路线中可能有obsticals。
-
好的,先生。所以现在帮助我实现这一目标
-
不清楚你尝试的方法有什么问题,你期望什么结果,你得到了什么?
标签: android