searchRideRoute method

Future<RideRouteResult> searchRideRoute ({@required LatLng from, @required LatLng to, int mode: 0 })

骑行路径规划

Implementation

static Future<RideRouteResult> searchRideRoute({
  @required LatLng from,
  @required LatLng to,
  int mode = 0,
}) async {
  // 会在listener中关闭
  // ignore: close_sinks
  final _controller = StreamController<RideRouteResult>(sync: true);

  platform(
    android: (pool) async {
      // 起点
      final fromLatLng = await ObjectFactory_Android
          .createcom_amap_api_services_core_LatLonPoint__double__double(
        from.latitude,
        from.longitude,
      );
      // 终点
      final toLatLng = await ObjectFactory_Android
          .createcom_amap_api_services_core_LatLonPoint__double__double(
        to.latitude,
        to.longitude,
      );

      // 起终点
      final fromAndTo = await ObjectFactory_Android
          .createcom_amap_api_services_route_RouteSearch_FromAndTo__com_amap_api_services_core_LatLonPoint__com_amap_api_services_core_LatLonPoint(
              fromLatLng, toLatLng);

      // 创建请求对象
      final query = await ObjectFactory_Android
          .createcom_amap_api_services_route_RouteSearch_RideRouteQuery__com_amap_api_services_route_RouteSearch_FromAndTo__int(
        fromAndTo,
        mode,
      );

      // 获取android上下文
      final context = await ObjectFactory_Android.getandroid_app_Activity();

      // 创建搜索对象
      _androidRouteSearch = await ObjectFactory_Android
          .createcom_amap_api_services_route_RouteSearch__android_content_Context(
              context);

      // 设置回调
      await _androidRouteSearch
          .setRouteSearchListener(_AndroidSearchListener(_controller));

      // 开始搜索
      await _androidRouteSearch.calculateRideRouteAsyn(query);

      // 局部变量从HEAP中解除引用
      pool..add(fromLatLng)..add(toLatLng)..add(fromAndTo)..add(query);
    },
    ios: (pool) async {
      _iosSearch = await ObjectFactory_iOS.createAMapSearchAPI();

      // 创建起点
      final fromLatLng = await ObjectFactory_iOS.createAMapGeoPoint();
      await fromLatLng.set_latitude(from.latitude);
      await fromLatLng.set_longitude(from.longitude);
      // 创建终点
      final toLatLng = await ObjectFactory_iOS.createAMapGeoPoint();
      await toLatLng.set_latitude(to.latitude);
      await toLatLng.set_longitude(to.longitude);

      // 设置回调
      await _iosSearch.set_delegate(_IOSSearchListener(_controller));

      // 创建搜索请求
      final request =
          await ObjectFactory_iOS.createAMapRidingRouteSearchRequest();
      // 设置起点
      await request.set_origin(fromLatLng);
      // 设置终点
      await request.set_destination(toLatLng);
      // 设置模式
      await request.set_type(mode);

      // 开始搜索
      await _iosSearch.AMapRidingRouteSearch(request);

      // 局部变量从HEAP中解除引用
      pool..add(fromLatLng)..add(toLatLng)..add(request);
    },
  );
  return _controller.stream.first;
}