Posted in Python onFebruary 16, 2014
/** * 计算两点之间距离 * @param _lat1 - start纬度 * @param _lon1 - start经度 * @param _lat2 - end纬度 * @param _lon2 - end经度 * @return km(四舍五入) */ public static double getDistance(double _lat1,double _lon1, double _lat2,double _lon2){ double lat1 = (Math.PI/180)*_lat1; double lat2 = (Math.PI/180)*_lat2; double lon1 = (Math.PI/180)*_lon1; double lon2 = (Math.PI/180)*_lon2; //地球半径 double R = 6378.1; double d = Math.acos(Math.sin(lat1)*Math.sin(lat2)+Math.cos(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1))*R; return new BigDecimal(d).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue(); } public static void main(String[] args) { System.out.println(getDistance(45.73990, 126.55893,45.73876, 126.55037)); }
python根据经纬度计算距离示例
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@