calculateDistance method

Future<double> calculateDistance(
  1. LatLng point1,
  2. LatLng point2
)

计算两点间的直线距离

计算点1point1和点2point2的距离

Implementation

static Future<double> calculateDistance(LatLng point1, LatLng point2) async {
  return platform(
    android: (pool) async {
      // 点1
      final _location1 = await AmapMapFluttifyFactoryAndroid
          .createcom_amap_api_maps_model_LatLng__double__double(
              point1.latitude, point1.longitude);
      // 点2
      final _location2 = await AmapMapFluttifyFactoryAndroid
          .createcom_amap_api_maps_model_LatLng__double__double(
              point2.latitude, point2.longitude);

      // 计算结果
      final result = await com_amap_api_maps_AMapUtils.calculateLineDistance(
          _location1, _location2);

      // 释放两个点
      pool..add(_location1)..add(_location2);

      return result;
    },
    ios: (pool) async {
      // 点1
      final _location1 =
          await PlatformFactoryIOS.createCLLocationCoordinate2D(
              point1.latitude, point1.longitude);
      final mapPoint1 = await MAMapPointForCoordinate(_location1);

      // 点2
      final _location2 =
          await PlatformFactoryIOS.createCLLocationCoordinate2D(
              point2.latitude, point2.longitude);
      final mapPoint2 = await MAMapPointForCoordinate(_location2);

      // 计算结果
      final result = await MAMetersBetweenMapPoints(mapPoint1, mapPoint2);

      // 释放两个点相关的数据
      pool..add(_location1)..add(_location2)..add(mapPoint1)..add(mapPoint2);

      return result;
    },
  );
}