lbs计算2点距离

/**
* 计算两点距离
*/
public class GeoTool {
/**

*/
private static final double EARTH_RADIUS = 6378.137;

/***
* 计算两点间的距离
* @param lat1 
* @param lon1
* @param lat2 
* @param lon2 
* @return
*/
public static double getPointDistance(double lat1, double lon1, double lat2, double lon2) {
double result = 0;
double radLat1 = radian(lat1);
double ratlat2 = radian(lat2);
double a = radian(lat1) - radian(lat2);
double b = radian(lon1) - radian(lon2);
result = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
+ Math.cos(radLat1) * Math.cos(ratlat2)
* Math.pow(Math.sin(b / 2), 2)));
result = result * EARTH_RADIUS;
result = Math.round(result * 1000);
return result;
}

//  转换为弧度
private static double radian(double d) {
return (d * Math.PI) / 180.00;
}

/**
* 获取geoHash
* @param lat 
* @param lon
* @return
*/
public static String geoHash(double lat,double lon){
return Geohash.encode(lat, lon);
}
}

你可能感兴趣的:(LBS)