iOS 调起地图App进行导航(百度,高德,系统自带高德)URL API方式

在开发中需要用到地图。有两种方法,一种是导入地图 (百度,高德)地图 SDK,一种是使用调起 客户端。

但是需要用到一些高级功能的时候,如果使用 SDK 开发,就是一件折磨人的事情。 SDK 还是不如直接使用他们原生的 APP 来的好!

以我在开发中使用导航功能为例,我就没有使用 SDK 进行开发,而是直接调用 (百度,高德,系统自带高德)APP。这样还给了客户多重选择。更加减少了引入 SDK 使 APP 臃肿的问题。如果使用百度或高德的调起方法配置起来感觉比较麻烦 ,还好他们都提供了 URL API 的方式,这种方式觉得稍微简单一点

下面将具体使用贴出代码如下:更多使用参考(百度,高德)官方文档

demo:http://download.csdn.net/detail/qq_26598821/9484647

1,App 调起百度地图路线规划进行导航。百度 URL API :http://lbsyun.baidu.com/index.php?title=uri/api/ios

[objc]  view plain  copy
  1. #pragma mark ------------------------------ 导航 - 百度  
  2. -(void) onDaoHangForBaiDuMap  
  3. {  
  4.     //    百度地图如何调起APP进行导航  
  5. //    mode  导航模式,固定为transit、driving、walking,分别表示公交、驾车和步行  
  6.     NSString * modeBaiDu = @"driving";  
  7.     switch (_seleIndex) {  
  8.         case 1:  
  9.         {  
  10.             modeBaiDu = @"transit";  
  11.         }  
  12.             break;  
  13.         case 2:  
  14.         {  
  15.             modeBaiDu = @"driving";  
  16.         }  
  17.             break;  
  18.         case 3:  
  19.         {  
  20.             modeBaiDu = @"walking";  
  21.         }  
  22.             break;  
  23.               
  24.         default:  
  25.             break;  
  26.     }  
  27.     NSString *url = [[NSString stringWithFormat:@"baidumap://map/direction?origin=%lf,%lf&destination=%f,%f&mode=%@&src=公司|APP",[SingleObject shareSingleObject].currentCoordinate.latitude,[SingleObject shareSingleObject].currentCoordinate.longitude,self.location.latitude,self.location.longitude,modeBaiDu] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;  
  28.       
  29. //    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];  
  30.       
  31.         if ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]])// -- 使用 canOpenURL:[NSURL URLWithString:@"baidumap://"] 判断不明白为什么为否。  
  32.         {  
  33.             [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];  
  34.         }else{  
  35.             [[[UIAlertView alloc]initWithTitle:@"没有安装百度地图" message:@"" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil nil] show];  
  36.         }  
  37.       
  38. }  

2,App 调起高德地图路线规划进行导航。高德 URL  API:http://lbs.amap.com/api/uri-api/ios-uri-explain/

[objc]  view plain  copy
  1. #pragma mark ------------------------------ 导航 - 高德  
  2. -(void) onDaoHangForGaoDeMap  
  3. {  
  4. //    m 驾车:0:速度最快,1:费用最少,2:距离最短,3:不走高速,4:躲避拥堵,5:不走高速且避免收费,6:不走高速且躲避拥堵,7:躲避收费和拥堵,8:不走高速躲避收费和拥堵 公交:0:最快捷,2:最少换乘,3:最少步行,5:不乘地铁 ,7:只坐地铁 ,8:时间短  是  
  5. //    t = 0:驾车 =1:公交 =2:步行  
  6.       
  7.     NSString * t = @"0";  
  8.     switch (_seleIndex) {  
  9.         case 1:  
  10.         {  
  11.             t = @"1";  
  12.         }  
  13.             break;  
  14.         case 2:  
  15.         {  
  16.             t = @"0";  
  17.         }  
  18.             break;  
  19.         case 3:  
  20.         {  
  21.             t = @"2";  
  22.         }  
  23.             break;  
  24.               
  25.         default:  
  26.             break;  
  27.     }  
  28.     //起点  
  29.     CLLocation * location = [[CLLocation alloc]initWithLatitude:[SingleObject shareSingleObject].currentCoordinate.latitude longitude:[SingleObject shareSingleObject].currentCoordinate.longitude];  
  30.     location = [location locationMarsFromBaidu];  
  31.       
  32.     CLLocationCoordinate2D coor =location.coordinate;  
  33.       
  34.     //目的地的位置  
  35.     CLLocation * location2 = [[CLLocation alloc]initWithLatitude:self.location.latitude longitude:self.location.longitude];  
  36.     location2 = [location2 locationMarsFromBaidu];  
  37.       
  38.     CLLocationCoordinate2D coor2 =location2.coordinate;  
  39. //    导航 URL:iosamap://navi?sourceApplication=%@&poiname=%@&lat=%lf&lon=%lf&dev=0&style=0",@"ABC"  
  40. //    路径规划 URL:iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=39.92848272&slon=116.39560823&sname=A&did=BGVIS2&dlat=39.98848272&dlon=116.47560823&dname=B&dev=0&m=0&t=0  
  41.     // -- 不能直接让用户进入导航,应该给用户更多的选择,所以先进行路径规划  
  42.       
  43.     NSString *url = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=%lf&slon=%lf&sname=我的位置&did=BGVIS2&dlat=%lf&dlon=%lf&dname=%@&dev=0&m=0&t=%@",coor.latitude,coor.longitude, coor2.latitude,coor2.longitude,self.mainTitle,t] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  
  44.       
  45.     if ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]) // -- 使用 canOpenURL:[NSURL URLWithString:@"iosamap://"] 判断不明白为什么为否。  
  46.     {  
  47.           
  48.         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];  
  49.           
  50.     }else{  
  51.         [[[UIAlertView alloc]initWithTitle:@"没有安装高德地图" message:@"" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil nil] show];  
  52.     }  
  53.       
  54.       
  55. }  

1,App 调起系统自带高德地图路线规划进行导航。

[objc]  view plain  copy
  1. #pragma mark ------------------------------ 导航 - iosMap  
  2. -(void) onDaoHangForIOSMap  
  3. {  
  4.     //起点  
  5.     CLLocation * location = [[CLLocation alloc]initWithLatitude:[SingleObject shareSingleObject].currentCoordinate.latitude longitude:[SingleObject shareSingleObject].currentCoordinate.longitude];  
  6.     location = [location locationMarsFromBaidu];  
  7.       
  8.     CLLocationCoordinate2D coor =location.coordinate;  
  9.     MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc]                         initWithCoordinate:coor  addressDictionary:nil]];  
  10.     currentLocation.name =@"我的位置";  
  11.       
  12.     //目的地的位置  
  13.     CLLocation * location2 = [[CLLocation alloc]initWithLatitude:self.location.latitude longitude:self.location.longitude];  
  14.     location2 = [location2 locationMarsFromBaidu];  
  15.       
  16.     CLLocationCoordinate2D coor2 =location2.coordinate;  
  17.     //    CLLocationCoordinate2D coords = self.location;  
  18.       
  19.       
  20.     MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coor2 addressDictionary:nil]];  
  21.       
  22.     toLocation.name = self.mainTitle;  
  23.       
  24.     NSArray *items = [NSArray arrayWithObjects:currentLocation, toLocation, nil nil];  
  25.     NSString * mode = MKLaunchOptionsDirectionsModeDriving;  
  26.     switch (_seleIndex) {  
  27.         case 1:  
  28.         {  
  29.             mode = MKLaunchOptionsDirectionsModeTransit;  
  30.         }  
  31.             break;  
  32.         case 2:  
  33.         {  
  34.             mode = MKLaunchOptionsDirectionsModeDriving;  
  35.         }  
  36.             break;  
  37.         case 3:  
  38.         {  
  39.             mode = MKLaunchOptionsDirectionsModeWalking;  
  40.         }  
  41.             break;  
  42.               
  43.         default:  
  44.             break;  
  45.     }  
  46.     NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:mode, MKLaunchOptionsMapTypeKey: [NSNumber                                 numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES };  
  47.     //打开苹果自身地图应用,并呈现特定的item  
  48.     [MKMapItem openMapsWithItems:items launchOptions:options];  
  49. }  
当中使用到了百度地图和高德地图的坐标转换。使用了一个扩展类来实现:

(转载自)ios 百度地图,火星坐标,地球坐标互转  http://www.oschina.net/code/snippet_2296716_48678



下面是工程中地图代码:
[objc]  view plain  copy
  1. //  
  2. //  RouteSearchDemoViewController.h  
  3. //  BaiduMapApiDemo  
  4. //  
  5. //  Copyright 2011 Baidu Inc. All rights reserved.  
  6. //  
  7.   
  8. /* 
  9.  //在上一个类进入本类 (地图显示界面) 
  10. RouteSearchDemoViewController *vc = [[RouteSearchDemoViewController alloc]init]; 
  11. vc.mainTitle = _shopDetailMOD.businessName; 
  12. vc.subTitle = _shopDetailMOD.businessAddress; 
  13. CLLocationCoordinate2D coor; 
  14. coor.latitude = [_shopDetailMOD.latitude floatValue]; 
  15. coor.longitude = [_shopDetailMOD.longitude floatValue]; 
  16. vc.location = coor; 
  17. vc.hidesBottomBarWhenPushed = YES; 
  18. [self.navigationController pushViewController:vc animated:YES]; 
  19. */  
  20.   
  21. #import <UIKit/UIKit.h>  
  22.   
  23. @interface RouteSearchDemoViewController : UIViewController<BMKMapViewDelegate, BMKRouteSearchDelegate,UIAlertViewDelegate> {  
  24.     IBOutlet BMKMapView* _mapView;  
  25.     BMKRouteSearch* _routesearch;  
  26.     BMKPointAnnotation* _pointAnnotation;  
  27.     NSInteger _seleIndex;  
  28. }  
  29.   
  30. -(IBAction)onClickBusSearch;   // 公交  
  31. -(IBAction)onClickDriveSearch; // 自驾  
  32. -(IBAction)onClickWalkSearch;  // 步行  
  33. - (IBAction)onClickRidingSearch:(id)sender;  //骑行  
  34.   
  35. @property(strongnonatomicNSString * mainTitle;  
  36. @property(strongnonatomicNSString * subTitle;  
  37. @property(assign, nonatomic) CLLocationCoordinate2D location;  
  38. @end  
[objc]  view plain  copy
  1. //  
  2. //  RouteSearchDemoViewController.mm  
  3. //  BaiduMapApiDemo  
  4. //  
  5. //  Copyright 2011 Baidu Inc. All rights reserved.  
  6. //  
  7.   
  8. #import "RouteSearchDemoViewController.h"  
  9. #import "UIImage+Rotate.h"  
  10. #import "CLLocation+YCLocation.h"  
  11. #import <MapKit/MapKit.h>  
  12.   
  13. #define MYBUNDLE_NAME @ "mapapi.bundle"  
  14. #define MYBUNDLE_PATH [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: MYBUNDLE_NAME]  
  15. #define MYBUNDLE [NSBundle bundleWithPath: MYBUNDLE_PATH]  
  16.   
  17. @interface RouteAnnotation : BMKPointAnnotation  
  18. {  
  19.     int _type; ///<0:起点 1:终点 2:公交 3:地铁 4:驾乘 5:途经点  
  20.     int _degree;  
  21. }  
  22.   
  23. @property (nonatomicint type;  
  24. @property (nonatomicint degree;  
  25. @end  
  26.   
  27. @implementation RouteAnnotation  
  28.   
  29. @synthesize type = _type;  
  30. @synthesize degree = _degree;  
  31. @end  
  32.   
  33.   
  34. @implementation RouteSearchDemoViewController  
  35.   
  36. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.  
  37. - (void)viewDidLoad {  
  38.     [super viewDidLoad];  
  39.     //适配ios7  
  40.     if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0))  
  41.     {  
  42. //        self.edgesForExtendedLayout=UIRectEdgeNone;  
  43.         self.navigationController.navigationBar.translucent = NO;  
  44.     }  
  45.       
  46. //    _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 64)];  
  47. //    [self.view addSubview: _mapView];  
  48.       
  49. //    _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放  
  50.       
  51.     [self addPointAnnotation:self.location];  
  52.       
  53.     _routesearch = [[BMKRouteSearch alloc]init];  
  54.     _routesearch.delegate = self;  
  55.     _seleIndex = 0;  
  56.       
  57. }  
  58.   
  59. - (NSString *)title {  
  60.     return self.mainTitle;  
  61. }  
  62. -(void)addPointAnnotation:(CLLocationCoordinate2D )location {  
  63.     _pointAnnotation = [[BMKPointAnnotation alloc]init];  
  64.     //    _pointAnnotation = [[BMKPointAnnotation alloc]init];  
  65.     _pointAnnotation.coordinate = location;  
  66.     _pointAnnotation.title = self.mainTitle;  
  67.     _pointAnnotation.subtitle = self.subTitle;  
  68.       
  69.     [_mapView addAnnotation:_pointAnnotation];  
  70.     [_mapView selectAnnotation:_pointAnnotation animated:YES];  
  71.     [_mapView setRegion:BMKCoordinateRegionMake(location, BMKCoordinateSpanMake(0.010.01))];  
  72.     [_mapView setCenterCoordinate:location animated:NO];   //使地图移动到定位的地方  
  73. }  
  74. -(void)viewWillAppear:(BOOL)animated {  
  75.     [_mapView viewWillAppear];  
  76.     _mapView.delegate = self// 此处记得不用的时候需要置nil,否则影响内存的释放  
  77.     _routesearch.delegate = self// 此处记得不用的时候需要置nil,否则影响内存的释放  
  78. }  
  79.   
  80. -(void)viewWillDisappear:(BOOL)animated {  
  81.     [_mapView viewWillDisappear];  
  82.     _mapView.delegate = nil// 不用时,置nil  
  83.     _routesearch.delegate = nil// 不用时,置nil  
  84. }  
  85.   
  86.   
  87. - (void)didReceiveMemoryWarning {  
  88.     // Releases the view if it doesn't have a superview.  
  89.     [super didReceiveMemoryWarning];  
  90.       
  91.     // Release any cached data, images, etc. that aren't in use.  
  92. }  
  93.   
  94. - (void)viewDidUnload {  
  95.     [super viewDidUnload];  
  96.     // Release any retained subviews of the main view.  
  97.     // e.g. self.myOutlet = nil;  
  98. }  
  99.   
  100.   
  101. - (void)dealloc {  
  102.     if (_routesearch != nil) {  
  103.         _routesearch = nil;  
  104.     }  
  105.     if (_mapView) {  
  106.         _mapView = nil;  
  107.     }  
  108. }  
  109.   
  110. - (void)wayPointDemo {  
  111.       
  112. //    WayPointRouteSearchDemoViewController * wayPointCont = [[WayPointRouteSearchDemoViewController alloc]init];  
  113. //    wayPointCont.title = @"驾车途经点";  
  114. //    UIBarButtonItem *customLeftBarButtonItem = [[UIBarButtonItem alloc] init];  
  115. //    customLeftBarButtonItem.title = @"返回";  
  116. //    self.navigationItem.backBarButtonItem = customLeftBarButtonItem;  
  117. //    [self.navigationController pushViewController:wayPointCont animated:YES];  
  118. }  
  119.   
  120. #pragma mark - BMKMapViewDelegate  
  121.   
  122. - (BMKAnnotationView *)mapView:(BMKMapView *)view viewForAnnotation:(id <BMKAnnotation>)annotation  
  123. {  
  124.     if ([annotation isKindOfClass:[RouteAnnotation class]]) {  
  125.         return [self getRouteAnnotationView:view viewForAnnotation:(RouteAnnotation*)annotation];  
  126.     }  
  127.     return nil;  
  128. }  
  129.   
  130. - (BMKOverlayView*)mapView:(BMKMapView *)map viewForOverlay:(id<BMKOverlay>)overlay  
  131. {  
  132.     if ([overlay isKindOfClass:[BMKPolyline class]]) {  
  133.         BMKPolylineView* polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay];  
  134.         polylineView.fillColor = [[UIColor alloc] initWithRed:0 green:1 blue:1 alpha:1];  
  135.         polylineView.strokeColor = [[UIColor alloc] initWithRed:0 green:0 blue:1 alpha:0.7];  
  136.         polylineView.lineWidth = 3.0;  
  137.         return polylineView;  
  138.     }  
  139.     return nil;  
  140. }  
  141.   
  142. #pragma mark - BMKRouteSearchDelegate  
  143.   
  144. - (void)onGetTransitRouteResult:(BMKRouteSearch*)searcher result:(BMKTransitRouteResult*)result errorCode:(BMKSearchErrorCode)error  
  145. {  
  146.     NSArray* array = [NSArray arrayWithArray:_mapView.annotations];  
  147.     [_mapView removeAnnotations:array];  
  148.     array = [NSArray arrayWithArray:_mapView.overlays];  
  149.     [_mapView removeOverlays:array];  
  150.     NSLog(@"%d",error);  
  151.     if (error == BMK_SEARCH_NO_ERROR) {  
  152.         BMKTransitRouteLine* plan = (BMKTransitRouteLine*)[result.routes objectAtIndex:0];  
  153.         // 计算路线方案中的路段数目  
  154.         NSInteger size = [plan.steps count];  
  155.         int planPointCounts = 0;  
  156.         for (int i = 0; i < size; i++) {  
  157.             BMKTransitStep* transitStep = [plan.steps objectAtIndex:i];  
  158.             if(i==0){  
  159.                 RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  160.                 item.coordinate = plan.starting.location;  
  161.                 item.title = @"起点";  
  162.                 item.type = 0;  
  163.                 [_mapView addAnnotation:item]; // 添加起点标注  
  164.                   
  165.             }else if(i==size-1){  
  166.                 RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  167.                 item.coordinate = plan.terminal.location;  
  168.                 item.title = @"终点";  
  169.                 item.type = 1;  
  170.                 [_mapView addAnnotation:item]; // 添加起点标注  
  171.             }  
  172.             RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  173.             item.coordinate = transitStep.entrace.location;  
  174.             item.title = transitStep.instruction;  
  175.             item.type = 3;  
  176.             [_mapView addAnnotation:item];  
  177.               
  178.             //轨迹点总数累计  
  179.             planPointCounts += transitStep.pointsCount;  
  180.         }  
  181.           
  182.         //轨迹点  
  183.         BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts];  
  184.         int i = 0;  
  185.         for (int j = 0; j < size; j++) {  
  186.             BMKTransitStep* transitStep = [plan.steps objectAtIndex:j];  
  187.             int k=0;  
  188.             for(k=0;k<transitStep.pointsCount;k++) {  
  189.                 temppoints[i].x = transitStep.points[k].x;  
  190.                 temppoints[i].y = transitStep.points[k].y;  
  191.                 i++;  
  192.             }  
  193.               
  194.         }  
  195.         // 通过points构建BMKPolyline  
  196.         BMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts];  
  197.         [_mapView addOverlay:polyLine]; // 添加路线overlay  
  198.         delete []temppoints;  
  199.         [self mapViewFitPolyLine:polyLine];  
  200.     }  
  201. }  
  202. - (void)onGetDrivingRouteResult:(BMKRouteSearch*)searcher result:(BMKDrivingRouteResult*)result errorCode:(BMKSearchErrorCode)error  
  203. {  
  204.     NSArray* array = [NSArray arrayWithArray:_mapView.annotations];  
  205.     [_mapView removeAnnotations:array];  
  206.     array = [NSArray arrayWithArray:_mapView.overlays];  
  207.     [_mapView removeOverlays:array];  
  208.     if (error == BMK_SEARCH_NO_ERROR) {  
  209.         BMKDrivingRouteLine* plan = (BMKDrivingRouteLine*)[result.routes objectAtIndex:0];  
  210.         // 计算路线方案中的路段数目  
  211.         NSInteger size = [plan.steps count];  
  212.         int planPointCounts = 0;  
  213.         for (int i = 0; i < size; i++) {  
  214.             BMKDrivingStep* transitStep = [plan.steps objectAtIndex:i];  
  215.             if(i==0){  
  216.                 RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  217.                 item.coordinate = plan.starting.location;  
  218.                 item.title = @"起点";  
  219.                 item.type = 0;  
  220.                 [_mapView addAnnotation:item]; // 添加起点标注  
  221.                   
  222.             }else if(i==size-1){  
  223.                 RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  224.                 item.coordinate = plan.terminal.location;  
  225.                 item.title = @"终点";  
  226.                 item.type = 1;  
  227.                 [_mapView addAnnotation:item]; // 添加起点标注  
  228.             }  
  229.             //添加annotation节点  
  230.             RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  231.             item.coordinate = transitStep.entrace.location;  
  232.             item.title = transitStep.entraceInstruction;  
  233.             item.degree = transitStep.direction * 30;  
  234.             item.type = 4;  
  235.             [_mapView addAnnotation:item];  
  236.               
  237.             //轨迹点总数累计  
  238.             planPointCounts += transitStep.pointsCount;  
  239.         }  
  240.         // 添加途经点  
  241.         if (plan.wayPoints) {  
  242.             for (BMKPlanNode* tempNode in plan.wayPoints) {  
  243.                 RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  244.                 item = [[RouteAnnotation alloc]init];  
  245.                 item.coordinate = tempNode.pt;  
  246.                 item.type = 5;  
  247.                 item.title = tempNode.name;  
  248.                 [_mapView addAnnotation:item];  
  249.             }  
  250.         }  
  251.         //轨迹点  
  252.         BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts];  
  253.         int i = 0;  
  254.         for (int j = 0; j < size; j++) {  
  255.             BMKDrivingStep* transitStep = [plan.steps objectAtIndex:j];  
  256.             int k=0;  
  257.             for(k=0;k<transitStep.pointsCount;k++) {  
  258.                 temppoints[i].x = transitStep.points[k].x;  
  259.                 temppoints[i].y = transitStep.points[k].y;  
  260.                 i++;  
  261.             }  
  262.               
  263.         }  
  264.         // 通过points构建BMKPolyline  
  265.         BMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts];  
  266.         [_mapView addOverlay:polyLine]; // 添加路线overlay  
  267.         delete []temppoints;  
  268.         [self mapViewFitPolyLine:polyLine];  
  269.     }  
  270. }  
  271.   
  272. - (void)onGetWalkingRouteResult:(BMKRouteSearch*)searcher result:(BMKWalkingRouteResult*)result errorCode:(BMKSearchErrorCode)error  
  273. {  
  274.     NSArray* array = [NSArray arrayWithArray:_mapView.annotations];  
  275.     [_mapView removeAnnotations:array];  
  276.     array = [NSArray arrayWithArray:_mapView.overlays];  
  277.     [_mapView removeOverlays:array];  
  278.     NSLog(@"%d",error);  
  279.     if (error == BMK_SEARCH_NO_ERROR) {  
  280.         BMKWalkingRouteLine* plan = (BMKWalkingRouteLine*)[result.routes objectAtIndex:0];  
  281.         NSInteger size = [plan.steps count];  
  282.         int planPointCounts = 0;  
  283.         for (int i = 0; i < size; i++) {  
  284.             BMKWalkingStep* transitStep = [plan.steps objectAtIndex:i];  
  285.             if(i==0){  
  286.                 RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  287.                 item.coordinate = plan.starting.location;  
  288.                 item.title = @"起点";  
  289.                 item.type = 0;  
  290.                 [_mapView addAnnotation:item]; // 添加起点标注  
  291.                   
  292.             }else if(i==size-1){  
  293.                 RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  294.                 item.coordinate = plan.terminal.location;  
  295.                 item.title = @"终点";  
  296.                 item.type = 1;  
  297.                 [_mapView addAnnotation:item]; // 添加起点标注  
  298.             }  
  299.             //添加annotation节点  
  300.             RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  301.             item.coordinate = transitStep.entrace.location;  
  302.             item.title = transitStep.entraceInstruction;  
  303.             item.degree = transitStep.direction * 30;  
  304.             item.type = 4;  
  305.             [_mapView addAnnotation:item];  
  306.               
  307.             //轨迹点总数累计  
  308.             planPointCounts += transitStep.pointsCount;  
  309.         }  
  310.           
  311.         //轨迹点  
  312.         BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts];  
  313.         int i = 0;  
  314.         for (int j = 0; j < size; j++) {  
  315.             BMKWalkingStep* transitStep = [plan.steps objectAtIndex:j];  
  316.             int k=0;  
  317.             for(k=0;k<transitStep.pointsCount;k++) {  
  318.                 temppoints[i].x = transitStep.points[k].x;  
  319.                 temppoints[i].y = transitStep.points[k].y;  
  320.                 i++;  
  321.             }  
  322.               
  323.         }  
  324.         // 通过points构建BMKPolyline  
  325.         BMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts];  
  326.         [_mapView addOverlay:polyLine]; // 添加路线overlay  
  327.         delete []temppoints;  
  328.         [self mapViewFitPolyLine:polyLine];  
  329.     }  
  330. }  
  331.   
  332. /** 
  333.  *返回骑行搜索结果 
  334.  *@param searcher 搜索对象 
  335.  *@param result 搜索结果,类型为BMKRidingRouteResult 
  336.  *@param error 错误号,@see BMKSearchErrorCode 
  337.  */  
  338. //- (void)onGetRidingRouteResult:(BMKRouteSearch *)searcher result:(BMKRidingRouteResult *)result errorCode:(BMKSearchErrorCode)error {  
  339. //    NSLog(@"onGetRidingRouteResult error:%d", (int)error);  
  340. //    NSArray* array = [NSArray arrayWithArray:_mapView.annotations];  
  341. //    [_mapView removeAnnotations:array];  
  342. //    array = [NSArray arrayWithArray:_mapView.overlays];  
  343. //    [_mapView removeOverlays:array];  
  344. //    if (error == BMK_SEARCH_NO_ERROR) {  
  345. //        BMKRidingRouteLine* plan = (BMKRidingRouteLine*)[result.routes objectAtIndex:0];  
  346. //        NSInteger size = [plan.steps count];  
  347. //        int planPointCounts = 0;  
  348. //        for (int i = 0; i < size; i++) {  
  349. //            BMKRidingStep* transitStep = [plan.steps objectAtIndex:i];  
  350. //            if (i == 0) {  
  351. //                RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  352. //                item.coordinate = plan.starting.location;  
  353. //                item.title = @"起点";  
  354. //                item.type = 0;  
  355. //                [_mapView addAnnotation:item]; // 添加起点标注  
  356. //            } else if(i==size-1){  
  357. //                RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  358. //                item.coordinate = plan.terminal.location;  
  359. //                item.title = @"终点";  
  360. //                item.type = 1;  
  361. //                [_mapView addAnnotation:item]; // 添加起点标注  
  362. //            }  
  363. //            //添加annotation节点  
  364. //            RouteAnnotation* item = [[RouteAnnotation alloc]init];  
  365. //            item.coordinate = transitStep.entrace.location;  
  366. //            item.title = transitStep.instruction;  
  367. //            item.degree = (int)transitStep.direction * 30;  
  368. //            item.type = 4;  
  369. //            [_mapView addAnnotation:item];  
  370. //              
  371. //            //轨迹点总数累计  
  372. //            planPointCounts += transitStep.pointsCount;  
  373. //        }  
  374. //          
  375. //        //轨迹点  
  376. //        BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts];  
  377. //        int i = 0;  
  378. //        for (int j = 0; j < size; j++) {  
  379. //            BMKRidingStep* transitStep = [plan.steps objectAtIndex:j];  
  380. //            int k=0;  
  381. //            for(k=0;k<transitStep.pointsCount;k++) {  
  382. //                temppoints[i].x = transitStep.points[k].x;  
  383. //                temppoints[i].y = transitStep.points[k].y;  
  384. //                i++;  
  385. //            }  
  386. //              
  387. //        }  
  388. //        // 通过points构建BMKPolyline  
  389. //        BMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts];  
  390. //        [_mapView addOverlay:polyLine]; // 添加路线overlay  
  391. //        delete []temppoints;  
  392. //        [self mapViewFitPolyLine:polyLine];  
  393. //    }  
  394. //}  
  395.   
  396.   
  397. #pragma mark ------------------------ 公交  
  398.   
  399. -(IBAction)onClickBusSearch  
  400. {  
  401.     _seleIndex = 1;  
  402.     CLLocationCoordinate2D coor;  
  403.     coor.latitude = [SingleObject shareSingleObject].currentCoordinate.latitude;  
  404.     coor.longitude = [SingleObject shareSingleObject].currentCoordinate.longitude;  
  405.       
  406.     BMKPlanNode* start = [[BMKPlanNode alloc]init];  
  407.     start.pt = coor;  
  408.     BMKPlanNode* end = [[BMKPlanNode alloc]init];  
  409.     end.pt = self.location;  
  410.       
  411.     BMKTransitRoutePlanOption *transitRouteSearchOption = [[BMKTransitRoutePlanOption alloc]init];  
  412.     transitRouteSearchOption.city= [SingleObject shareSingleObject].selectedCityObject.cityName;  
  413.     transitRouteSearchOption.from = start;  
  414.     transitRouteSearchOption.to = end;  
  415.     BOOL flag = [_routesearch transitSearch:transitRouteSearchOption];  
  416.       
  417.     if(flag)  
  418.     {  
  419.         NSLog(@"bus检索发送成功");  
  420.     }  
  421.     else  
  422.     {  
  423.         NSLog(@"bus检索发送失败");  
  424.     }  
  425. }  
  426.   
  427. //-(IBAction)textFiledReturnEditing:(id)sender {  
  428. //    [sender resignFirstResponder];  
  429. //}  
  430. #pragma mark ------------------------------ 自驾  
  431. -(IBAction)onClickDriveSearch  
  432. {  
  433.     _seleIndex = 2;  
  434.     CLLocationCoordinate2D coor;  
  435.     coor.latitude = [SingleObject shareSingleObject].currentCoordinate.latitude;  
  436.     coor.longitude = [SingleObject shareSingleObject].currentCoordinate.longitude;  
  437.   
  438.     BMKPlanNode* start = [[BMKPlanNode alloc]init];  
  439.       
  440.     start.pt = coor;  
  441.     BMKPlanNode* end = [[BMKPlanNode alloc]init];  
  442.     end.pt = self.location;  
  443.       
  444.     BMKDrivingRoutePlanOption *drivingRouteSearchOption = [[BMKDrivingRoutePlanOption alloc]init];  
  445.     drivingRouteSearchOption.from = start;  
  446.     drivingRouteSearchOption.to = end;  
  447.     BOOL flag = [_routesearch drivingSearch:drivingRouteSearchOption];  
  448.     if(flag)  
  449.     {  
  450.         NSLog(@"car检索发送成功");  
  451.     }  
  452.     else  
  453.     {  
  454.         NSLog(@"car检索发送失败");  
  455.     }  
  456.   
  457. }  
  458. #pragma mark ------------------------------ 步行  
  459. -(IBAction)onClickWalkSearch  
  460. {  
  461.     _seleIndex = 3;  
  462.     CLLocationCoordinate2D coor;  
  463.     coor.latitude = [SingleObject shareSingleObject].currentCoordinate.latitude;  
  464.     coor.longitude = [SingleObject shareSingleObject].currentCoordinate.longitude;  
  465.       
  466.     BMKPlanNode* start = [[BMKPlanNode alloc]init];  
  467.       
  468.     start.pt = coor;  
  469.     BMKPlanNode* end = [[BMKPlanNode alloc]init];  
  470.     end.pt = self.location;  
  471.       
  472.       
  473.     BMKWalkingRoutePlanOption *walkingRouteSearchOption = [[BMKWalkingRoutePlanOption alloc]init];  
  474.     walkingRouteSearchOption.from = start;  
  475.     walkingRouteSearchOption.to = end;  
  476.     BOOL flag = [_routesearch walkingSearch:walkingRouteSearchOption];  
  477.     if(flag)  
  478.     {  
  479.         NSLog(@"walk检索发送成功");  
  480.     }  
  481.     else  
  482.     {  
  483.         NSLog(@"walk检索发送失败");  
  484.     }  
  485.       
  486. }  
  487. #pragma mark ------------------------------ 导航  
  488. - (IBAction)onClickRidingSearch:(id)sender {  
  489.       
  490.     UIAlertView * aler = [[UIAlertView alloc]initWithTitle:@"请选择您要使用的导航地图" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"百度地图",@"高德地图",@"系统(高德)地图", nil nil];  
  491.     [aler show];  
  492.     aler.tag = 1213;  
  493. }  
  494. - (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{  
  495.     if (alertView.tag == 1213) {  
  496.         switch (buttonIndex) {  
  497.             case 0:  
  498.             {  
  499.                   
  500.             }  
  501.                 break;  
  502.             case 1:  
  503.             {  
  504.                 [self onDaoHangForBaiDuMap];  
  505.             }  
  506.                 break;  
  507.             case 2:  
  508.             {  
  509.                 [self onDaoHangForGaoDeMap];  
  510.             }  
  511.                 break;  
  512.             case 3:  
  513.             {  
  514.                 [self onDaoHangForIOSMap];  
  515.             }  
  516.                 break;  
  517.                   
  518.             default:  
  519.                 break;  
  520.         }  
  521.     }  
  522. }  
  523.   
  524. #pragma mark ------------------------------ 导航 - 百度  
  525. -(void) onDaoHangForBaiDuMap  
  526. {  
  527.     //    百度地图如何调起APP进行导航  
  528. //    mode  导航模式,固定为transit、driving、walking,分别表示公交、驾车和步行  
  529.     NSString * modeBaiDu = @"driving";  
  530.     switch (_seleIndex) {  
  531.         case 1:  
  532.         {  
  533.             modeBaiDu = @"transit";  
  534.         }  
  535.             break;  
  536.         case 2:  
  537.         {  
  538.             modeBaiDu = @"driving";  
  539.         }  
  540.             break;  
  541.         case 3:  
  542.         {  
  543.             modeBaiDu = @"walking";  
  544.         }  
  545.             break;  
  546.               
  547.         default:  
  548.             break;  
  549.     }  
  550.     NSString *url = [[NSString stringWithFormat:@"baidumap://map/direction?origin=%lf,%lf&destination=%f,%f&mode=%@&src=公司|APP",[SingleObject shareSingleObject].currentCoordinate.latitude,[SingleObject shareSingleObject].currentCoordinate.longitude,self.location.latitude,self.location.longitude,modeBaiDu] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;  
  551.       
  552. //    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];  
  553.       
  554.         if ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]])// -- 使用 canOpenURL:[NSURL URLWithString:@"baidumap://"] 判断不明白为什么为否。  
  555.         {  
  556.             [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];  
  557.         }else{  
  558.             [[[UIAlertView alloc]initWithTitle:@"没有安装百度地图" message:@"" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil nil] show];  
  559.         }  
  560.       
  561. }  
  562. #pragma mark ------------------------------ 导航 - 高德  
  563. -(void) onDaoHangForGaoDeMap  
  564. {  
  565. //    m 驾车:0:速度最快,1:费用最少,2:距离最短,3:不走高速,4:躲避拥堵,5:不走高速且避免收费,6:不走高速且躲避拥堵,7:躲避收费和拥堵,8:不走高速躲避收费和拥堵 公交:0:最快捷,2:最少换乘,3:最少步行,5:不乘地铁 ,7:只坐地铁 ,8:时间短  是  
  566. //    t = 0:驾车 =1:公交 =2:步行  
  567.       
  568.     NSString * t = @"0";  
  569.     switch (_seleIndex) {  
  570.         case 1:  
  571.         {  
  572.             t = @"1";  
  573.         }  
  574.             break;  
  575.         case 2:  
  576.         {  
  577.             t = @"0";  
  578.         }  
  579.             break;  
  580.         case 3:  
  581.         {  
  582.             t = @"2";  
  583.         }  
  584.             break;  
  585.               
  586.         default:  
  587.             break;  
  588.     }  
  589.     //起点  
  590.     CLLocation * location = [[CLLocation alloc]initWithLatitude:[SingleObject shareSingleObject].currentCoordinate.latitude longitude:[SingleObject shareSingleObject].currentCoordinate.longitude];  
  591.     location = [location locationMarsFromBaidu];  
  592.       
  593.     CLLocationCoordinate2D coor =location.coordinate;  
  594.       
  595.     //目的地的位置  
  596.     CLLocation * location2 = [[CLLocation alloc]initWithLatitude:self.location.latitude longitude:self.location.longitude];  
  597.     location2 = [location2 locationMarsFromBaidu];  
  598.       
  599.     CLLocationCoordinate2D coor2 =location2.coordinate;  
  600. //    导航 URL:iosamap://navi?sourceApplication=%@&poiname=%@&lat=%lf&lon=%lf&dev=0&style=0",@"APP"  
  601. //    路径规划 URL:iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=39.92848272&slon=116.39560823&sname=A&did=BGVIS2&dlat=39.98848272&dlon=116.47560823&dname=B&dev=0&m=0&t=0  
  602.     // -- 不能直接让用户进入导航,应该给用户更多的选择,所以先进行路径规划  
  603.       
  604.     NSString *url = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=%lf&slon=%lf&sname=我的位置&did=BGVIS2&dlat=%lf&dlon=%lf&dname=%@&dev=0&m=0&t=%@",coor.latitude,coor.longitude, coor2.latitude,coor2.longitude,self.mainTitle,t] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  
  605.       
  606.     if ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]) // -- 使用 canOpenURL:[NSURL URLWithString:@"iosamap://"] 判断不明白为什么为否。  
  607.     {  
  608.           
  609.         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];  
  610.           
  611.     }else{  
  612.         [[[UIAlertView alloc]initWithTitle:@"没有安装高德地图" message:@"" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil nil] show];  
  613.     }  
  614.       
  615.       
  616. }  
  617. #pragma mark ------------------------------ 导航 - iosMap  
  618. -(void) onDaoHangForIOSMap  
  619. {  
  620.     //起点  
  621.     CLLocation * location = [[CLLocation alloc]initWithLatitude:[SingleObject shareSingleObject].currentCoordinate.latitude longitude:[SingleObject shareSingleObject].currentCoordinate.longitude];  
  622.     location = [location locationMarsFromBaidu];  
  623.       
  624.     CLLocationCoordinate2D coor =location.coordinate;  
  625.     MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc]                         initWithCoordinate:coor  addressDictionary:nil]];  
  626.     currentLocation.name =@"我的位置";  
  627.       
  628.     //目的地的位置  
  629.     CLLocation * location2 = [[CLLocation alloc]initWithLatitude:self.location.latitude longitude:self.location.longitude];  
  630.     location2 = [location2 locationMarsFromBaidu];  
  631.       
  632.     CLLocationCoordinate2D coor2 =location2.coordinate;  
  633.     //    CLLocationCoordinate2D coords = self.location;  
  634.       
  635.       
  636.     MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coor2 addressDictionary:nil]];  
  637.       
  638.     toLocation.name = self.mainTitle;  
  639.       
  640.     NSArray *items = [NSArray arrayWithObjects:currentLocation, toLocation, nil nil];  
  641.     NSString * mode = MKLaunchOptionsDirectionsModeDriving;  
  642.     switch (_seleIndex) {  
  643.         case 1:  
  644.         {  
  645.             mode = MKLaunchOptionsDirectionsModeTransit;  
  646.         }  
  647.             break;  
  648.         case 2:  
  649.         {  
  650.             mode = MKLaunchOptionsDirectionsModeDriving;  
  651.         }  
  652.             break;  
  653.         case 3:  
  654.         {  
  655.             mode = MKLaunchOptionsDirectionsModeWalking;  
  656.         }  
  657.             break;  
  658.               
  659.         default:  
  660.             break;  
  661.     }  
  662.     NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:mode, MKLaunchOptionsMapTypeKey: [NSNumber                                 numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES };  
  663.     //打开苹果自身地图应用,并呈现特定的item  
  664.     [MKMapItem openMapsWithItems:items launchOptions:options];  
  665. }  
  666.   
  667. #pragma mark - 私有  
  668.   
  669. - (NSString*)getMyBundlePath1:(NSString *)filename  
  670. {  
  671.       
  672.     NSBundle * libBundle = MYBUNDLE ;  
  673.     if ( libBundle && filename ){  
  674.         NSString * s=[[libBundle resourcePath ] stringByAppendingPathComponent : filename];  
  675.         return s;  
  676.     }  
  677.     return nil ;  
  678. }  
  679.   
  680. - (BMKAnnotationView*)getRouteAnnotationView:(BMKMapView *)mapview viewForAnnotation:(RouteAnnotation*)routeAnnotation  
  681. {  
  682.     BMKAnnotationView* view = nil;  
  683.     switch (routeAnnotation.type) {  
  684.         case 0:  
  685.         {  
  686.             view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"start_node"];  
  687.             if (view == nil) {  
  688.                 view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"start_node"];  
  689.                 view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_start.png"]];  
  690.                 view.centerOffset = CGPointMake(0, -(view.frame.size.height * 0.5));  
  691.                 view.canShowCallout = TRUE;  
  692.             }  
  693.             view.annotation = routeAnnotation;  
  694.         }  
  695.             break;  
  696.         case 1:  
  697.         {  
  698.             view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"end_node"];  
  699.             if (view == nil) {  
  700.                 view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"end_node"];  
  701.                 view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_end.png"]];  
  702.                 view.centerOffset = CGPointMake(0, -(view.frame.size.height * 0.5));  
  703.                 view.canShowCallout = TRUE;  
  704.             }  
  705.             view.annotation = routeAnnotation;  
  706.         }  
  707.             break;  
  708.         case 2:  
  709.         {  
  710.             view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"bus_node"];  
  711.             if (view == nil) {  
  712.                 view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"bus_node"];  
  713.                 view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_bus.png"]];  
  714.                 view.canShowCallout = TRUE;  
  715.             }  
  716.             view.annotation = routeAnnotation;  
  717.         }  
  718.             break;  
  719.         case 3:  
  720.         {  
  721.             view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"rail_node"];  
  722.             if (view == nil) {  
  723.                 view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"rail_node"];  
  724.                 view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_rail.png"]];  
  725.                 view.canShowCallout = TRUE;  
  726.             }  
  727.             view.annotation = routeAnnotation;  
  728.         }  
  729.             break;  
  730.         case 4:  
  731.         {  
  732.             view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"route_node"];  
  733.             if (view == nil) {  
  734.                 view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"route_node"];  
  735.                 view.canShowCallout = TRUE;  
  736.             } else {  
  737.                 [view setNeedsDisplay];  
  738.             }  
  739.               
  740.             UIImage* image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_direction.png"]];  
  741. //            view.image = [image imageRotatedByDegrees:routeAnnotation.degree];  
  742.             view.annotation = routeAnnotation;  
  743.               
  744.         }  
  745.             break;  
  746.         case 5:  
  747.         {  
  748.             view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"waypoint_node"];  
  749.             if (view == nil) {  
  750.                 view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"waypoint_node"];  
  751.                 view.canShowCallout = TRUE;  
  752.             } else {  
  753.                 [view setNeedsDisplay];  
  754.             }  
  755.               
  756.             UIImage* image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_waypoint.png"]];  
  757.             view.image = [image imageRotatedByDegrees:routeAnnotation.degree];  
  758.             view.annotation = routeAnnotation;  
  759.         }  
  760.             break;  
  761.         default:  
  762.             break;  
  763.     }  
  764.       
  765.     return view;  
  766. }  
  767. //  
  768. 根据polyline设置地图范围  
  769. - (void)mapViewFitPolyLine:(BMKPolyline *) polyLine {  
  770.     CGFloat ltX, ltY, rbX, rbY;  
  771.     if (polyLine.pointCount < 1) {  
  772.         return;  
  773.     }  
  774.     BMKMapPoint pt = polyLine.points[0];  
  775.     ltX = pt.x, ltY = pt.y;  
  776.     rbX = pt.x, rbY = pt.y;  
  777.     for (int i = 1; i < polyLine.pointCount; i++) {  
  778.         BMKMapPoint pt = polyLine.points[i];  
  779.         if (pt.x < ltX) {  
  780.             ltX = pt.x;  
  781.         }  
  782.         if (pt.x > rbX) {  
  783.             rbX = pt.x;  
  784.         }  
  785.         if (pt.y > ltY) {  
  786.             ltY = pt.y;  
  787.         }  
  788.         if (pt.y < rbY) {  
  789.             rbY = pt.y;  
  790.         }  
  791.     }  
  792.     BMKMapRect rect;  
  793.     rect.origin = BMKMapPointMake(ltX , ltY);  
  794.     rect.size = BMKMapSizeMake(rbX - ltX, rbY - ltY);  
  795.     [_mapView setVisibleMapRect:rect];  
  796.     _mapView.zoomLevel = _mapView.zoomLevel - 0.3;  
  797. }  
  798.   
  799. @end  

地图界面 XIB 


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值