JAVA 获取两个坐标的距离
Double x1 = 12.998898;
Double y1 = 99.854678;
Double x2 = 12.098658;
Double y2 = 99.124235;
//获取两个坐标之间的距离
GlobalCoordinates source = new GlobalCoordinates(x1, y1);
GlobalCoordinates target = new GlobalCoordinates(x2, y2);
//创建GeodeticCalculator,调用计算方法,传入坐标系、经纬度用于计算距离
GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere, source, target);
Double distance = geoCurve.getEllipsoidalDistance();
//格式化-保留两位小数
DecimalFormat df = new DecimalFormat("#.00");
String distanceStr = df.format(distance/1000);
System.out.println("在这里插入代码片Sphere坐标系计算结果:"+distanceStr + "km");