## 1、导入依赖的jar

``````<!--计算距离依赖的jar-->
<dependency>
<groupId>org.gavaghan</groupId>
<artifactId>geodesy</artifactId>
<version>1.1.3</version>
</dependency>``````

## 2、写一个简单的工具类

``````import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

/**
* 计算经纬度直线距离
* @author: caoju
*/
public class DistanceUtil {

public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid) {
//创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo);
return geoCurve.getEllipsoidalDistance();
}

}``````

## 3、传入经纬度进行测试

``````import com.cj.test.mytestproject.utils.DistanceUtil;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GlobalCoordinates;

public class MeterTest {

public static void main(String[] args) {
//用户当前坐标
GlobalCoordinates userSource = new GlobalCoordinates(39.939557, 116.409515);
//店铺位置坐标
GlobalCoordinates businessTarget = new GlobalCoordinates(39.939668, 116.393058);
double meterDouble = DistanceUtil.getDistanceMeter(userSource, businessTarget, Ellipsoid.Sphere);
int meter = (int) meterDouble;
System.out.println(meter);
}

}``````

Java代码实现按照距离、评分、订单数排序