python根据经纬度计算距离示例

代码如下:

/** * 计算两点之间距离 * @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));}