【发布时间】:2016-02-22 21:05:00
【问题描述】:
我有两个 GPS 坐标,例如:(44.40239182909422, 8.930511474608954) 和 (30.297017883371236, 122.3822021484364)
我想知道这两点之间的距离(以米为单位)。我不知道第一个坐标是否大于第二个。
我正在尝试理解和修改此代码示例:
private double _distance(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(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515; // 60 is the number of minutes in a degree; //1.1515 is the number of statute miles in a nautical mile.One nautical mile is the length of one minute of latitude at the equator.
dist = dist * 1.609344;
return (dist);
}
为了计算“theta”,我添加了以下代码:
double theta = lon1 - lon2;
if(lon2>lon1)
theta = lon2 - lon1;
【问题讨论】:
-
用google maps api怎么样? goo.gl/IovoB8
-
不,我不能使用它们....:(
-
这是纬度和经度?
-
我在 Google 中输入了“纬度经度距离差”,没有引号,它似乎产生了大量相关点击。
标签: java