package com.opensesame.core.util;
public class DistanceUtil {
//测量两点的距离(fromPoint:经度纬度;toPoint:经度纬度)
public static long measureDistance(LatLon fromPoint, LatLon toPoint) {
double EARTH_RADIUS = 6378137;
long distance = 0l;
double startLongitude = Double.valueOf(fromPoint.getLongitude());
double startLatitude = Double.valueOf(fromPoint.getLatitude());
double endLongitude = Double.valueOf(toPoint.getLongitude());
double endLatitude = Double.valueOf(toPoint.getLatitude());
double radLatitude1 = startLatitude * Math.PI / 180.0;
double radLatitude2 = endLatitude * Math.PI / 180.0;
double a = Math.abs(radLatitude1 - radLatitude2);
double b = Math.abs(startLongitude * Math.PI / 180.0 - endLongitude * Math.PI / 180.0);
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
+ Math.cos(radLatitude1) * Math.cos(radLatitude2) * Math.pow(Math.sin(b / 2), 2)));
s = s * EARTH_RADIUS;
distance = Math.round(s * 10000) / 10000; // 返回距离单位是米
return distance;
}
// public static void main(String[]arg0){
// // 北京市朝阳区阜通东大街6号转换后经纬度:116.480881,39.989410
// // 天安门转换后经纬度:116.397499,39.908722
// LatLon f = new LatLon();
// LatLon t = new LatLon();
//
// f.setLongitude(Double.valueOf("123.437834"));
// f.setLatitude(Double.valueOf("41.756178"));
//
// t.setLongitude(Double.valueOf("123.435914"));
// t.setLatitude(Double.valueOf("41.760092"));
//
// System.out.println(measureDistance(t,f));
//
System.out.println(InspectionHouseUtil.firstInspectionTime(200.00,1,0)/60);
// }
}
java测量两点的距离
最新推荐文章于 2024-04-17 02:56:22 发布