package com.dahe.gldriver.utils

import com.amap.api.maps2d.AMapException
import com.amap.api.maps2d.model.LatLng
import com.dahe.mylibrary.base.SingletonNoPHolder

/**
 * @ClassName LocationUtils
 * @Author john
 * @Date 2024/3/4 15:53
 * @Description TODO
 */
class LocationUtils private constructor() {

    companion object : SingletonNoPHolder<LocationUtils>(::LocationUtils)


    fun getDistance(var0: LatLng?, var1: LatLng?): String {
        return if (var0 != null && var1 != null) {
            try {
                var var2: Double = var0.longitude
                var var4: Double = var0.latitude
                var var6: Double = var1.longitude
                var var8: Double = var1.latitude
                var2 *= 0.01745329251994329
                var4 *= 0.01745329251994329
                var6 *= 0.01745329251994329
                var8 *= 0.01745329251994329
                val var10 = Math.sin(var2)
                val var12 = Math.sin(var4)
                val var14 = Math.cos(var2)
                val var16 = Math.cos(var4)
                val var18 = Math.sin(var6)
                val var20 = Math.sin(var8)
                val var22 = Math.cos(var6)
                val var24 = Math.cos(var8)
                val var28 = DoubleArray(3)
                val var29 = DoubleArray(3)
                var28[0] = var16 * var14
                var28[1] = var16 * var10
                var28[2] = var12
                var29[0] = var24 * var22
                var29[1] = var24 * var18
                var29[2] = var20
                String.format(
                    "%.2f", (Math.asin(
                        Math.sqrt(
                            (var28[0] - var29[0]) * (var28[0] - var29[0]) +
                                    (var28[1] - var29[1]) * (var28[1] - var29[1]) + (var28[2] - var29[2]) * (var28[2] - var29[2])
                        ) / 2.0
                    )
                            * 1.27420015798544E7).toFloat() / 1000
                )
            } catch (var26: Throwable) {
                var26.printStackTrace()
                "0.00"
            }
        } else {
            try {
                throw AMapException("非法坐标值")
            } catch (var27: AMapException) {
                var27.printStackTrace()
                "0.00"
            }
        }
    }
}