货车出行路线规划 最后更新时间: 2021年01月22日
从搜索功能6.1.0 版本开始支持货车出行路线规划功能,货车出行路线规划的具体策略可参见服务文档。
第 1 步, 创建AMapTruckRouteSearchRequest
AMapTruckRouteSearchRequest *navi = [[AMapTruckRouteSearchRequest alloc] init];
let request = AMapTruckRouteSearchRequest()
第 2 步, 实现参数
详细参数可以参考AMapTruckRouteSearchRequest类的头文件。
navi.origin = [AMapGeoPoint locationWithLatitude:self.startCoordinate.latitude
longitude:self.startCoordinate.longitude];
navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationCoordinate.latitude
longitude:self.destinationCoordinate.longitude];
request.origin = AMapGeoPoint.location(withLatitude: CGFloat(startCoordinate.latitude), longitude: CGFloat(startCoordinate.longitude))
request.destination = AMapGeoPoint.location(withLatitude: CGFloat(destinationCoordinate.latitude), longitude: CGFloat(destinationCoordinate.longitude))
第 3 步,发送请求
使用AMapSearchAPI的AMapTruckRouteSearch接口
[self.search AMapTruckRouteSearch:navi];
search.aMapTruckRouteSearch(request)
第 4 步, 处理回调
在onRouteSearchDone回调中处理信息,货车路径归回时AMapRouteSearchResponse会返回货车相关信息,具体请查看AMapRoute的paths属性。
如果发生错误,会回调AMapSearchRequest:(id)request didFailWithError:(NSError *)error方法。
- (void)onRouteSearchDone:(AMapRouteSearchBaseRequest *)request response:(AMapRouteSearchResponse *)response { //解析response获取路径信息,具体解析见 Demo }
func onRouteSearchDone(_ request: AMapRouteSearchBaseRequest!, response: AMapRouteSearchResponse!) { //解析response获取路径信息 } }