getDistance static method

double getDistance(
  1. double lat1,
  2. double lng1,
  3. double lat2,
  4. double lng2,
)

根据两点经纬度 使用math 算出之间距离 https://blog.csdn.net/weixin_38025168/article/details/107491452

Implementation

static double getDistance(
    double lat1, double lng1, double lat2, double lng2) {
  /// 单位:米
  double def = 6378137.0;
  double radLat1 = _rad(lat1);
  double radLat2 = _rad(lat2);
  double a = radLat1 - radLat2;
  double b = _rad(lng1) - _rad(lng2);
  double s = 2 *
      asin(sqrt(pow(sin(a / 2), 2) +
          cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2)));
  return (s * def).roundToDouble() / 1000; // 返回千米
}