searchBusRoute method
公交出行路线规划
指定起点from
和终点to
进行计算, 还可以指定计算路径的模式mode
, 默认为最快捷. city
指定所在城市
nightflag
是否计算夜班车,默认为不计算,0:不计算,1:计算
Implementation
static Future<BusRouteResult> searchBusRoute({
@required LatLng from,
@required LatLng to,
@required String city,
int mode = 0,
int nightflag = 0,
}) async {
// 会在listener中关闭
// ignore: close_sinks
final _controller = StreamController<BusRouteResult>(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_BusRouteQuery__com_amap_api_services_route_RouteSearch_FromAndTo__int__String__int(
fromAndTo,
mode,
city,
nightflag,
);
// 获取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.calculateBusRouteAsyn(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.createAMapWalkingRouteSearchRequest();
// 设置起点
await request.set_origin(fromLatLng);
// 设置终点
await request.set_destination(toLatLng);
// 开始搜索
await _iosSearch.AMapWalkingRouteSearch(request);
// 局部变量从HEAP中解除引用
pool..add(fromLatLng)..add(toLatLng)..add(request);
},
);
return _controller.stream.first;
}