zoukankan      html  css  js  c++  java
  • 百度地图

    项目需要集成百度地图,那么关于如何集成百度地图的事,就自己去百度开放平台查看文档吧,这是非常简单的事,在这里就不多说了。

    那么下面我就说说我在这个demo里所做的事。

    首先,项目需要具备定位及计算两地的距离

    其次,项目需要根据两个地点来拿到所有路线,并且可根据不同的策略拿到对应的最佳路线。

    最后,需要拿到打车相关信息

    那么这里我就自己写了一个单例类,这是在内部处理所有的代理,外部可以非常方便地调用,如果有好的建议,请在评论中赐教,谢谢!

    1. //  
    2. //  HYBBaiduMapHelper.h  
    3. //  BaiduMapDemo  
    4. //  
    5. //  Created by 黄仪标 on 14/11/18.  
    6. //  Copyright (c) 2014年 黄仪标. All rights reserved.  
    7. //  
    8.   
    9. #import <Foundation/Foundation.h>  
    10. #import "BMapKit.h"  
    11.   
    12. typedef void (^HYBUserLocationCompletion)(BMKUserLocation *userLocation);  
    13. typedef void (^HYBRouteSearchCompletion)(BMKTransitRouteResult *result);  
    14.   
    15. /*! 
    16.  * @brief 百度地图相关API操作类 
    17.  * 
    18.  * @author huangyibiao 
    19.  */  
    20. @interface HYBBaiduMapHelper : NSObject  
    21.   
    22. + (HYBBaiduMapHelper *)shared;  
    23.   
    24. ///  
    25. /// 该方法在appdelegate的调用,在应用启动时,请求授权百度地图  
    26. - (BOOL)startWithAppKey:(NSString *)appKey;  
    27.   
    28. ///  
    29. /// 下面的几个方法是定位使用  
    30. - (void)locateInView:(UIView *)mapSuerView  
    31.                frame:(CGRect)frame  
    32.       withCompletion:(HYBUserLocationCompletion)completion;  
    33. - (void)viewWillAppear;  
    34. - (void)viewWillDisappear;  
    35. - (void)viewDidDeallocOrReceiveMemoryWarning;  
    36.   
    37. ///  
    38. /// 下面的方法是计算两地的距离  
    39. /// 返回距离单位为米  
    40. - (CLLocationDistance)distanceWithStartPoint:(CLLocationCoordinate2D)startPoint  
    41.                                     endPoint:(CLLocationCoordinate2D)endPoint;  
    42.   
    43. ///  
    44. /// 下面的方法是路线规划获取操作  
    45. /// 注意:不能同时调用下面的这三个方法,必须是先调用完一个,返回结果后,再继续调用别的,否则会覆盖前一个操作的数据  
    46.   
    47. /// 公交检索方法  
    48. /// 前两个参数,分别表示起点和终点的位置名称  
    49. /// 第三个参数,表示在哪个城市里检索  
    50. - (void)transitRouteSearchFrom:(BMKPlanNode *)startNode  
    51.                             to:(BMKPlanNode *)endNode  
    52.                           city:(NSString *)city  
    53.                  transitPolicy:(BMKTransitPolicy)transitPolicy  
    54.                     completion:(HYBRouteSearchCompletion)completion;  
    55.   
    56. /// 驾乘检索方法  
    57. /// 前两个参数,分别表示起点和终点的位置名称  
    58. - (void)driveRouteSearchFrom:(BMKPlanNode *)startNode  
    59.                           to:(BMKPlanNode *)endNode  
    60.                  drivePolicy:(BMKDrivingPolicy)drivePolicy  
    61.                   completion:(HYBRouteSearchCompletion)completion;  
    62.   
    63. /// 步行检索方法  
    64. /// 前两个参数,分别表示起点和终点的位置名称  
    65. - (void)walkRouteSearchFrom:(BMKPlanNode *)startNode  
    66.                          to:(BMKPlanNode *)endNode  
    67.                  completion:(HYBRouteSearchCompletion)completion;  
    68.   
    69. @end  
    1. //  
    2. //  HYBBaiduMapHelper.m  
    3. //  BaiduMapDemo  
    4. //  
    5. //  Created by 黄仪标 on 14/11/18.  
    6. //  Copyright (c) 2014年 黄仪标. All rights reserved.  
    7. //  
    8.   
    9. #import "HYBBaiduMapHelper.h"  
    10.   
    11. @interface HYBBaiduMapHelper () <BMKLocationServiceDelegate,  
    12. BMKGeneralDelegate,  
    13. BMKMapViewDelegate,  
    14. BMKRouteSearchDelegate> {  
    15.   BMKMapManager             *_mapManager;  
    16.   HYBUserLocationCompletion _locationCompletion;  
    17.   HYBRouteSearchCompletion  _routeSearchCompletion;  
    18.   BMKMapView                *_mapView;  
    19.   BMKLocationService        *_locationService;  
    20.   BMKRouteSearch            *_routeSearch;  
    21. }  
    22.   
    23. @end  
    24.   
    25. @implementation HYBBaiduMapHelper  
    26.   
    27. + (HYBBaiduMapHelper *)shared {  
    28.   static HYBBaiduMapHelper *baiduMapHelper = nil;  
    29.   static dispatch_once_t onceToken = 0;  
    30.     
    31.   dispatch_once(&onceToken, ^{  
    32.     if (!baiduMapHelper) {  
    33.       baiduMapHelper = [[[self class] alloc] init];  
    34.     }  
    35.   });  
    36.     
    37.   return baiduMapHelper;  
    38. }  
    39.   
    40. - (instancetype)init {  
    41.   if (self = [super init]) {  
    42.     _mapManager = [[BMKMapManager alloc] init];  
    43.   }  
    44.     
    45.   return self;  
    46. }  
    47.   
    48. - (BOOL)startWithAppKey:(NSString *)appKey {  
    49.   if (![appKey isKindOfClass:[NSString class]] || appKey.length == 0 || appKey == nil) {  
    50.     return NO;  
    51.   }  
    52.     
    53.   return [_mapManager start:appKey generalDelegate:self];  
    54. }  
    55.   
    56. - (void)locateInView:(UIView *)mapSuerView frame:(CGRect)frame withCompletion:(HYBUserLocationCompletion)completion {  
    57.   _locationCompletion = [completion copy];  
    58.     
    59.   [_locationService stopUserLocationService];  
    60.   _locationService = nil;  
    61.   _locationService.delegate = nil;  
    62.   _locationService = [[BMKLocationService alloc] init];  
    63.   [_locationService startUserLocationService];  
    64.     
    65.   if (_mapView) {  
    66.     [_mapView removeFromSuperview];  
    67.     _mapView = nil;  
    68.   }  
    69.   _mapView.delegate = nil;  
    70.   _mapView.showsUserLocation = NO;  
    71.   _mapView = [[BMKMapView alloc] initWithFrame:frame];  
    72.   [mapSuerView addSubview:_mapView];  
    73.     
    74.   _mapView.delegate = self;  
    75.   // 先关闭显示的定位图层  
    76.   _mapView.showsUserLocation = NO;  
    77.   // 设置定位的状态  
    78.   _mapView.userTrackingMode = BMKUserTrackingModeNone;  
    79.   _mapView.showsUserLocation = YES;  
    80.   return;  
    81. }  
    82.   
    83. - (void)viewWillAppear {  
    84.   [_mapView viewWillAppear];  
    85.     
    86.   _mapView.delegate = self;  
    87.   _locationService.delegate = self;  
    88.   _routeSearch.delegate = self;  
    89.   return;  
    90. }  
    91.   
    92. - (void)viewWillDisappear {  
    93.   [_mapView viewWillDisappear];  
    94.     
    95.   _mapView.delegate = nil;  
    96.   _locationService.delegate = nil;  
    97.   _routeSearch.delegate = nil;  
    98.   return;  
    99. }  
    100.   
    101. - (void)viewDidDeallocOrReceiveMemoryWarning {  
    102.   [self viewWillDisappear];  
    103.     
    104.   _mapView.showsUserLocation = NO;  
    105.   [_locationService stopUserLocationService];  
    106.   [_mapView removeFromSuperview];  
    107.   _mapView = nil;  
    108.     
    109.   _locationService = nil;  
    110.   _routeSearch.delegate = nil;  
    111.   _routeSearch = nil;  
    112.   return;  
    113. }  
    114.   
    115. ///  
    116. /// 计算两点的距离  
    117. - (CLLocationDistance)distanceWithStartPoint:(CLLocationCoordinate2D)startPoint endPoint:(CLLocationCoordinate2D)endPoint {  
    118.   BMKMapPoint point1 = BMKMapPointForCoordinate(startPoint);  
    119.   BMKMapPoint point2 = BMKMapPointForCoordinate(endPoint);  
    120.   CLLocationDistance distance = BMKMetersBetweenMapPoints(point1, point2);  
    121.   return distance;  
    122. }  
    123.   
    124. ///  
    125. /// 下面的方法是路线规划获取操作  
    126. /// 公交检索方法  
    127. /// 前两个参数,分别表示起点和终点的位置名称  
    128. /// 第三个参数,表示在哪个城市里检索  
    129. - (void)transitRouteSearchFrom:(BMKPlanNode *)startNode  
    130.                             to:(BMKPlanNode *)endNode  
    131.                           city:(NSString *)city  
    132.                  transitPolicy:(BMKTransitPolicy)transitPolicy  
    133.                     completion:(HYBRouteSearchCompletion)completion {  
    134.   _routeSearchCompletion = [completion copy];  
    135.     
    136.   if (_routeSearch == nil) {  
    137.     _routeSearch = [[BMKRouteSearch alloc] init];  
    138.   }  
    139.     
    140.   _routeSearch.delegate = self;  
    141.     
    142.   // 公交检索  
    143.   BMKTransitRoutePlanOption *transitRoutePlan = [[BMKTransitRoutePlanOption alloc] init];  
    144.   transitRoutePlan.city = city;  
    145.   transitRoutePlan.from = startNode;  
    146.   transitRoutePlan.to = endNode;  
    147.   transitRoutePlan.transitPolicy = transitPolicy;  
    148.     
    149.   if ([_routeSearch transitSearch:transitRoutePlan]) {  
    150.     NSLog(@"bus检索发送成功");  
    151.   } else {  
    152.     NSLog(@"bus检索发送失败");  
    153.   }  
    154.   return;  
    155. }  
    156.   
    157. /// 驾乘检索方法  
    158. /// 前两个参数,分别表示起点和终点的位置名称  
    159. - (void)driveRouteSearchFrom:(BMKPlanNode *)startNode  
    160.                           to:(BMKPlanNode *)endNode  
    161.                  drivePolicy:(BMKDrivingPolicy)drivePolicy  
    162.                   completion:(HYBRouteSearchCompletion)completion {  
    163.   _routeSearchCompletion = [completion copy];  
    164.     
    165.   if (_routeSearch == nil) {  
    166.     _routeSearch = [[BMKRouteSearch alloc] init];  
    167.   }  
    168.     
    169.   _routeSearch.delegate = self;  
    170.     
    171.   // 公交检索  
    172.   BMKDrivingRoutePlanOption *driveRoutePlan = [[BMKDrivingRoutePlanOption alloc] init];  
    173.   driveRoutePlan.from = startNode;  
    174.   driveRoutePlan.to = endNode;  
    175.   driveRoutePlan.drivingPolicy = drivePolicy;  
    176.     
    177.   if ([_routeSearch drivingSearch:driveRoutePlan]) {  
    178.     NSLog(@"drive 检索发送成功");  
    179.   } else {  
    180.     NSLog(@"drive 检索发送失败");  
    181.   }  
    182.   return;  
    183. }  
    184.   
    185. /// 步行检索方法  
    186. /// 前两个参数,分别表示起点和终点的位置名称  
    187. - (void)walkRouteSearchFrom:(BMKPlanNode *)startNode  
    188.                          to:(BMKPlanNode *)endNode  
    189.                  completion:(HYBRouteSearchCompletion)completion {  
    190.   _routeSearchCompletion = [completion copy];  
    191.     
    192.   if (_routeSearch == nil) {  
    193.     _routeSearch = [[BMKRouteSearch alloc] init];  
    194.   }  
    195.     
    196.   _routeSearch.delegate = self;  
    197.     
    198.   // 公交检索  
    199.   BMKWalkingRoutePlanOption *walkRoutePlan = [[BMKWalkingRoutePlanOption alloc] init];  
    200.   walkRoutePlan.from = startNode;  
    201.   walkRoutePlan.to = endNode;  
    202.     
    203.   if ([_routeSearch walkingSearch:walkRoutePlan]) {  
    204.     NSLog(@"walk 检索发送成功");  
    205.   } else {  
    206.     NSLog(@"walk 检索发送失败");  
    207.   }  
    208.   return;  
    209. }  
    210.   
    211. #pragma mark - BMKGeneralDelegate  
    212. - (void)onGetNetworkState:(int)iError {  
    213.   if (0 == iError) {  
    214.     NSLog(@"联网成功");  
    215.   } else {  
    216.     NSLog(@"onGetNetworkState %d",iError);  
    217.   }  
    218.   return;  
    219. }  
    220.   
    221. - (void)onGetPermissionState:(int)iError {  
    222.   if (0 == iError) {  
    223.     NSLog(@"百度地图授权成功");  
    224.   } else {  
    225.     NSLog(@"onGetPermissionState %d",iError);  
    226.   }  
    227.   return;  
    228. }  
    229.   
    230. #pragma mark - BMKLocationServiceDelegate  
    231. /** 
    232.  *在将要启动定位时,会调用此函数 
    233.  */  
    234. - (void)willStartLocatingUser {  
    235.   NSLog(@"location start");  
    236.   return;  
    237. }  
    238.   
    239. /** 
    240.  *在停止定位后,会调用此函数 
    241.  */  
    242. - (void)didStopLocatingUser {  
    243.   NSLog(@"user location stop");  
    244.   return;  
    245. }  
    246.   
    247. /** 
    248.  *用户方向更新后,会调用此函数 
    249.  *@param userLocation 新的用户位置 
    250.  */  
    251. - (void)didUpdateUserHeading:(BMKUserLocation *)userLocation {  
    252.   NSLog(@"user derection change");  
    253.   [_mapView updateLocationData:userLocation];  
    254.   return;  
    255. }  
    256.   
    257. /** 
    258.  *用户位置更新后,会调用此函数 
    259.  *@param userLocation 新的用户位置 
    260.  */  
    261. - (void)didUpdateUserLocation:(BMKUserLocation *)userLocation {  
    262.   NSLog(@"didUpdateUserLocation lat %f,long %f",  
    263.         userLocation.location.coordinate.latitude,  
    264.         userLocation.location.coordinate.longitude);  
    265.   [_mapView updateLocationData:userLocation];  
    266.   if (_locationCompletion) {  
    267.     _locationCompletion(userLocation);  
    268.   }  
    269.     
    270.   [_locationService stopUserLocationService];  
    271.   return;  
    272. }  
    273.   
    274. /** 
    275.  *定位失败后,会调用此函数 
    276.  *@param error 错误号 
    277.  */  
    278. - (void)didFailToLocateUserWithError:(NSError *)error {  
    279.   if (_locationCompletion) {  
    280.     _locationCompletion(nil);  
    281.   }  
    282.     
    283.   [_locationService stopUserLocationService];  
    284.   return;  
    285. }  
    286.   
    287. #pragma mark - BMKRouteSearchDelegate  
    288. - (void)onGetTransitRouteResult:(BMKRouteSearch *)searcher  
    289.                          result:(BMKTransitRouteResult *)result  
    290.                       errorCode:(BMKSearchErrorCode)error {  
    291.   if (error == BMK_SEARCH_NO_ERROR) { // 检索成功的处理  
    292.     for (BMKTransitRouteLine *line in result.routes) {  
    293.       NSLog(@"-----------------------------------------------------");  
    294.       NSLog(@"  时间:%2d %2d:%2d:%2d 长度: %d米",  
    295.             line.duration.dates,  
    296.             line.duration.hours,  
    297.             line.duration.minutes,  
    298.             line.duration.seconds,  
    299.             line.distance);  
    300.       for (BMKTransitStep *step in line.steps) {  
    301.         NSLog(@"%@     %@    %@    %@    %@",  
    302.               step.entrace.title,  
    303.               step.exit.title,  
    304.               step.instruction,  
    305.               (step.stepType == BMK_BUSLINE ? @"公交路段" : (step.stepType == BMK_SUBWAY ? @"地铁路段" : @"步行路段")),  
    306.               [NSString stringWithFormat:@"名称:%@  所乘站数:%d   全程价格:%d  区间价格:%d",  
    307.                step.vehicleInfo.title,  
    308.                step.vehicleInfo.passStationNum,  
    309.                step.vehicleInfo.totalPrice,  
    310.                step.vehicleInfo.zonePrice]);  
    311.       }  
    312.     }  
    313.       
    314.     // 打车信息  
    315.     NSLog(@"打车信息------------------------------------------");  
    316.     NSLog(@"路线打车描述信息:%@  总路程: %d米    总耗时:约%f分钟  每千米单价:%f元  全程总价:约%d元",  
    317.           result.taxiInfo.desc,  
    318.           result.taxiInfo.distance,  
    319.           result.taxiInfo.duration / 60.0,  
    320.           result.taxiInfo.perKMPrice,  
    321.           result.taxiInfo.totalPrice);  
    322.       
    323.       
    324.   } else if (error == BMK_SEARCH_AMBIGUOUS_ROURE_ADDR) { // 检索地址有岐义,可获取推荐地址  
    325.     // 获取建议检索起终点  
    326.     NSLog(@"无检索结果,返回了建议检索信息");  
    327.       
    328.     NSLog(@"起点推荐信息:--------------------------------");  
    329.     for (BMKPoiInfo *info in result.suggestAddrResult.startPoiList) {  
    330.       NSLog(@"POI名称:%@     POI地址:%@     POI所在城市:%@", info.name, info.address, info.city);  
    331.     }  
    332.       
    333.     NSLog(@"终点推荐信息:--------------------------------");  
    334.     for (BMKPoiInfo *info in result.suggestAddrResult.endPoiList) {  
    335.       NSLog(@"POI名称:%@     POI地址:%@     POI所在城市:%@", info.name, info.address, info.city);  
    336.     }  
    337.   } else {  
    338.     NSLog(@"无公交检索结果 ");  
    339.   }  
    340.     
    341.     
    342.   // 回调block根据实际需要返回,可修改返回结构  
    343.   if (_routeSearchCompletion) {  
    344.     _routeSearchCompletion(nil); // 这里只是返回空,这个需要根据实际需要返回  
    345.   }  
    346.   return;  
    347. }  
    348.   
    349. - (void)onGetDrivingRouteResult:(BMKRouteSearch *)searcher  
    350.                          result:(BMKDrivingRouteResult *)result  
    351.                       errorCode:(BMKSearchErrorCode)error {  
    352.   if (error == BMK_SEARCH_NO_ERROR) { // 检索成功的处理  
    353.     for (BMKDrivingRouteLine *line in result.routes) {  
    354.       NSLog(@"-----------------------------------------------------");  
    355.       NSLog(@"  时间:%2d %2d:%2d:%2d 长度: %d米",  
    356.             line.duration.dates,  
    357.             line.duration.hours,  
    358.             line.duration.minutes,  
    359.             line.duration.seconds,  
    360.             line.distance);  
    361.       for (BMKDrivingStep *step in line.steps) {  
    362.         NSLog(@"入口:%@   出口:%@   路段总体指示信息:%@    入口信息:%@    出口信息:%@  转弯数:%d",  
    363.               step.entrace.title,  
    364.               step.exit.title,  
    365.               step.instruction,  
    366.               step.entraceInstruction,  
    367.               step.exitInstruction,  
    368.               step.numTurns);  
    369.       }  
    370.     }  
    371.   } else if (error == BMK_SEARCH_AMBIGUOUS_ROURE_ADDR) { // 检索地址有岐义,可获取推荐地址  
    372.     // 获取建议检索起终点  
    373.     NSLog(@"无检索结果,返回了建议检索信息");  
    374.       
    375.     NSLog(@"起点推荐信息:--------------------------------");  
    376.     for (BMKPoiInfo *info in result.suggestAddrResult.startPoiList) {  
    377.       NSLog(@"POI名称:%@     POI地址:%@     POI所在城市:%@", info.name, info.address, info.city);  
    378.     }  
    379.       
    380.     NSLog(@"终点推荐信息:--------------------------------");  
    381.     for (BMKPoiInfo *info in result.suggestAddrResult.endPoiList) {  
    382.       NSLog(@"POI名称:%@     POI地址:%@     POI所在城市:%@", info.name, info.address, info.city);  
    383.     }  
    384.   } else {  
    385.     NSLog(@"无公交检索结果 ");  
    386.   }  
    387.     
    388.     
    389.   // 回调block根据实际需要返回,可修改返回结构  
    390.   if (_routeSearchCompletion) {  
    391.     _routeSearchCompletion(nil); // 这里只是返回空,这个需要根据实际需要返回  
    392.   }  
    393.   return;  
    394. }  
    395.   
    396. - (void)onGetWalkingRouteResult:(BMKRouteSearch *)searcher  
    397.                          result:(BMKWalkingRouteResult *)result  
    398.                       errorCode:(BMKSearchErrorCode)error {  
    399.   if (error == BMK_SEARCH_NO_ERROR) { // 检索成功的处理  
    400.     for (BMKDrivingRouteLine *line in result.routes) {  
    401.       NSLog(@"步行检索结果 :-----------------------------------------------------");  
    402.       NSLog(@"  时间:%2d %2d:%2d:%2d 长度: %d米",  
    403.             line.duration.dates,  
    404.             line.duration.hours,  
    405.             line.duration.minutes,  
    406.             line.duration.seconds,  
    407.             line.distance);  
    408.       for (BMKWalkingStep *step in line.steps) {  
    409.         NSLog(@"入口:%@   出口:%@   路段总体指示信息:%@    入口信息:%@    出口信息:%@",  
    410.               step.entrace.title,  
    411.               step.exit.title,  
    412.               step.instruction,  
    413.               step.entraceInstruction,  
    414.               step.exitInstruction);  
    415.       }  
    416.     }  
    417.   } else if (error == BMK_SEARCH_AMBIGUOUS_ROURE_ADDR) { // 检索地址有岐义,可获取推荐地址  
    418.     // 获取建议检索起终点  
    419.     NSLog(@"无检索结果,返回了建议检索信息");  
    420.       
    421.     NSLog(@"起点推荐信息:--------------------------------");  
    422.     for (BMKPoiInfo *info in result.suggestAddrResult.startPoiList) {  
    423.       NSLog(@"POI名称:%@     POI地址:%@     POI所在城市:%@", info.name, info.address, info.city);  
    424.     }  
    425.       
    426.     NSLog(@"终点推荐信息:--------------------------------");  
    427.     for (BMKPoiInfo *info in result.suggestAddrResult.endPoiList) {  
    428.       NSLog(@"POI名称:%@     POI地址:%@     POI所在城市:%@", info.name, info.address, info.city);  
    429.     }  
    430.   } else {  
    431.     NSLog(@"无公交检索结果 ");  
    432.   }  
    433.     
    434.     
    435.   // 回调block根据实际需要返回,可修改返回结构  
    436.   if (_routeSearchCompletion) {  
    437.     _routeSearchCompletion(nil); // 这里只是返回空,这个需要根据实际需要返回  
    438.   }  
    439.   return;  
    440. }  
    441.   
    442. @end  



    下面就是测试一个我们的数据是否真的拿到了:

    1. //  
    2. //  RootViewController.m  
    3. //  BaiduMapDemo  
    4. //  
    5. //  Created by 黄仪标 on 14/11/18.  
    6. //  Copyright (c) 2014年 黄仪标. All rights reserved.  
    7. //  
    8.   
    9. #import "RootViewController.h"  
    10. #import "HYBBaiduMapHelper.h"  
    11. #import "BMapKit.h"  
    12.   
    13. @interface RootViewController ()  
    14.   
    15. @end  
    16.   
    17. @implementation RootViewController  
    18.   
    19. - (void)viewDidLoad {  
    20.   [super viewDidLoad];  
    21.     
    22.   // 功能1、定位  
    23.   [[HYBBaiduMapHelper shared] locateInView:self.view frame:self.view.bounds withCompletion:^(BMKUserLocation *userLocation) {  
    24.     NSLog(@"%f  %f", userLocation.location.coordinate.latitude, userLocation.location.coordinate.longitude);  
    25.   }];  
    26.     
    27.   // 功能2:”计算距离  
    28.  CLLocationDistance distance = [[HYBBaiduMapHelper shared] distanceWithStartPoint:CLLocationCoordinate2DMake(39.915,116.404)  
    29.                                             endPoint:CLLocationCoordinate2DMake(38.915,115.404)];  
    30.   NSLog(@"distance = %fm", distance);  
    31.     
    32.   // 功能3:公交检索  
    33.   BMKPlanNode *startNode = [[BMKPlanNode alloc] init];  
    34.   startNode.name = @"梆子井";  
    35.   startNode.cityName = @"北京";  
    36.     
    37.   BMKPlanNode *endNode = [[BMKPlanNode alloc] init];  
    38.   endNode.name = @"金长安大厦";  
    39.   endNode.cityName = @"北京";  
    40.     
    41.   // 功能3:公交检索  
    42.   [[HYBBaiduMapHelper shared] transitRouteSearchFrom:startNode to:endNode city:@"北京" transitPolicy:BMK_TRANSIT_TRANSFER_FIRST completion:^(BMKTransitRouteResult *result) {  
    43.     // 功能4:驾乘检索  
    44.     [[HYBBaiduMapHelper shared] driveRouteSearchFrom:startNode to:endNode drivePolicy:BMK_DRIVING_TIME_FIRST  completion:^(BMKTransitRouteResult *result) {  
    45.       // 功能5:步行检索  
    46.       [[HYBBaiduMapHelper shared] walkRouteSearchFrom:startNode to:endNode completion:^(BMKTransitRouteResult *result) {  
    47.         ;  
    48.       }];  
    49.     }];  
    50.   }];  
    51.   return;  
    52. }  
    53.   
    54. - (void)viewWillAppear:(BOOL)animated {  
    55.   [super viewWillAppear:animated];  
    56.     
    57.   [[HYBBaiduMapHelper shared] viewWillAppear];  
    58.     
    59.   return;  
    60. }  
    61.   
    62. - (void)viewWillDisappear:(BOOL)animated {  
    63.   [super viewWillDisappear:animated];  
    64.     
    65.   [[HYBBaiduMapHelper shared] viewWillDisappear];  
    66.   return;  
    67. }  
    68.   
    69. - (void)didReceiveMemoryWarning {  
    70.   [super didReceiveMemoryWarning];  
    71.     
    72.   [[HYBBaiduMapHelper shared] viewDidDeallocOrReceiveMemoryWarning];  
    73.   return;  
    74. }  
    75.   
    76. - (void)dealloc {  
    77.   [[HYBBaiduMapHelper shared] viewDidDeallocOrReceiveMemoryWarning];  
    78.   return;  
    79. }  
    80.   
    81.   
    82. @end  

    想要深入研究的同学,可以去官网看官方提供的Demo,

    如果想在我的demo之上进一步追加或者修改功能,可以下载本demo

    来源:http://blog.csdn.net/woaifen3344/article/details/41284495

  • 相关阅读:
    CSS 中的字体兼容写法:用CSS为英文和中文字体分别设置不同的字体
    利用vue-cropper做的关于图片裁剪、压缩、上传、预览等做的一个公共组件
    解决浏览器拦截弹出窗口问题
    详解Vue中的nextTick
    vue里ref ($refs)用法
    vue组件的hover事件模拟、给第三方组件绑定事件不生效问题
    JS实现千分位
    JS实现异步编程的4种方法
    Cas_个人理解
    zabbix_监控_邮件预警
  • 原文地址:https://www.cnblogs.com/guangleijia/p/4758243.html
Copyright © 2011-2022 走看看