java 已知两个地点经纬度算两个地点的距离
1.POM文件导入jar包
<!--计算两地经纬度距离-->
<dependency>
<groupId>org.gavaghan</groupId>
<artifactId>geodesy</artifactId>
<version>1.1.3</version>
</dependency>
2.调用方法
//longitude1定位纬度,latitude1 定位经度,longitude2 定位维度,latitude2 定位经度
public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2){
GlobalCoordinates source = new GlobalCoordinates(longitude1, latitude1);
GlobalCoordinates target = new GlobalCoordinates(longitude2, latitude2);
GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve( Ellipsoid.Sphere, source, target);
double meter1=geoCurve.getEllipsoidalDistance()/1000;
return meter1;
}
3.方法执行后返回两个经纬度之间的距离单位为km;
希望能帮到你,加油~,记得点赞噢,蟹蟹.