这其实有一个求球面距离的公式,忘了,百度到的……嘿嘿
[img]http://dl2.iteye.com/upload/attachment/0086/3910/4f412205-11a9-398a-8c18-935ff31ca3ba.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0086/3910/4f412205-11a9-398a-8c18-935ff31ca3ba.png[/img]
// lat是纬度,lung是经度
//a=Lat1 – Lat2 为两点纬度之差 b=Lung1 -Lung2 为两点经度之差;
//6378.137(KM) 为地球半径 - -@
//恩,结果也是km……
//另外,google的api其实已经实现好了的
// 计算两点距离
private final double EARTH_RADIUS = 6378137.0;
private double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) {
double radLat1 = (lat_a * Math.PI / 180.0);
double radLat2 = (lat_b * Math.PI / 180.0);
double a = radLat1 - radLat2;
double b = (lng_a - lng_b) * Math.PI / 180.0;
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
+ Math.cos(radLat1) * Math.cos(radLat2)
* Math.pow(Math.sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = Math.round(s * 10000) / 10000;
return s;
}