kotlin
package com.zo.util
import org.gavaghan.geodesy.Ellipsoid
import org.gavaghan.geodesy.GeodeticCalculator
import org.gavaghan.geodesy.GlobalCoordinates
object CalculateDistanceUtil {
// 获取两个经纬度的距离(米)
fun getDistance(
sourceLat: Double,
sourceLng: Double,
targetLat: Double,
targetLng: Double,
ellipsoid: Ellipsoid? = Ellipsoid.WGS84
): Double {
val source = GlobalCoordinates(sourceLat, sourceLng)
val target = GlobalCoordinates(targetLat, targetLng)
//创建GeodeticCalculator,调用计算方法,传入坐标系、经纬度用于计算距离
val geoCurve = GeodeticCalculator().calculateGeodeticCurve(ellipsoid, source