iOS 腾讯地图算步行路线距离

2022-02-16  本文已影响0人  hashakey

直接上代码


<QMSSearchDelegate>
@property (nonatomic, strong) QMSSearcher *mySearcher;

- (QMSSearcher *)mySearcher {
    if (!_mySearcher) {
        _mySearcher = [[QMSSearcher alloc]initWithDelegate:self];
    }
    return _mySearcher;
}

- (void)viewDidLoad {//1
    [super viewDidLoad];
    QMSWalkingRouteSearchOption *WalkingOpt = [[QMSWalkingRouteSearchOption alloc] init];
        [WalkingOpt setFrom:[NSString stringWithFormat:@"%f,%f",Alatitude,Alongitude]];
        [WalkingOpt setTo:[NSString stringWithFormat:@"%f,%f",Blatitude,Blongitude]];
        [self.mySearcher searchWithWalkingRouteSearchOption:WalkingOpt];

  QMSBicyclingRouteSearchOption *BicyclingOpt = [[QMSBicyclingRouteSearchOption alloc] init];
    [BicyclingOpt setFrom:[NSString stringWithFormat:@"%f,%f",Alatitude,Alongitude]];
    [BicyclingOpt setTo:[NSString stringWithFormat:@"%f,%f",Blatitude,Blongitude]];
    [self.mySearcher searchWithBicyclingRouteSearchOption:BicyclingOpt];

    QMSDrivingRouteSearchOption *drivingOpt = [[QMSDrivingRouteSearchOption alloc] init];
    [drivingOpt setPolicyWithType:QMSDrivingRoutePolicyTypeLeastTime];
    [drivingOpt setFrom:[NSString stringWithFormat:@"%f,%f",Alatitude,Alongitude]];
    [drivingOpt setTo:[NSString stringWithFormat:@"%f,%f",Blatitude,Blongitude]];
    [self.mySearcher searchWithDrivingRouteSearchOption:drivingOpt];
}

#pragma mark - Search Delegates
//error
- (void)searchWithSearchOption:(QMSSearchOption *)searchOption didFailWithError:(NSError *)error
{
    NSLog(@"error:%@", error);
}
//步行路径结果回调
- (void)searchWithWalkingRouteSearchOption:(QMSWalkingRouteSearchOption *)walkingRouteSearchOption didRecevieResult:(QMSWalkingRouteSearchResult *)walkingRouteSearchResult
{
    NSLog(@"Walking result:%@. count:%ld", walkingRouteSearchResult, walkingRouteSearchResult.routes.count);
    QMSRoutePlan *routeLine = [walkingRouteSearchResult.routes firstObject];
    float dis = routeLine.distance;
    NSString *scopeStr = [NSString stringWithFormat:@"%.3f", dis/1000];
    NSLog(@"disdisdisdisdis %f   %@",dis,scopeStr);
}

//骑行路径结果回调
- (void)searchWithBicyclingRouteSearchOption:(QMSBicyclingRouteSearchOption *)bicyclingRouteSearchOption didRecevieResult:(QMSBicyclingRouteSearchResult *)bicyclingRouteSearchResult {
    NSLog(@"Walking result:%@. count:%ld", bicyclingRouteSearchResult, bicyclingRouteSearchResult.routes.count);
  QMSRoutePlan *routeLine = [bicyclingRouteSearchResult.routes firstObject];
    float dis = routeLine.distance;
    NSString *scopeStr = [NSString stringWithFormat:@"%.3f", dis/1000];
    NSLog(@"disdisdisdisdis %f   %@",dis,scopeStr);
}
//驾车路径结果回调
- (void)searchWithDrivingRouteSearchOption:(QMSDrivingRouteSearchOption *)drivingRouteSearchOption didRecevieResult:(QMSDrivingRouteSearchResult *)drivingRouteSearchResult {
    NSLog(@"Walking result:%@. count:%ld", drivingRouteSearchOption, drivingRouteSearchResult.routes.count);
  QMSRoutePlan *routeLine = [drivingRouteSearchResult.routes firstObject];
    float dis = routeLine.distance;
    NSString *scopeStr = [NSString stringWithFormat:@"%.3f", dis/1000];
    NSLog(@"disdisdisdisdis %f   %@",dis,scopeStr);
}

上一篇下一篇

猜你喜欢

热点阅读