iOS 6苹果地图应用(MapKit)-打开外部应用

原始地址:iOS 6苹果地图应用(MapKit)-打开外部应用

在iOS 6中,苹果把google地图换成了自己的地图,看上去不错。


效果图:

iOS 6以下(google map web)



iOS 6

  


实现代码



头文件导入和判断版本的预定义声明

  1. #import <MapKit/MapKit.h>  
  2.   
  3. define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)  


具体实现
  1. CLLocationCoordinate2D coords1 =  
  2. CLLocationCoordinate2DMake(30.691793,104.088264);  
  3. CLLocationCoordinate2D coords2 =  
  4. CLLocationCoordinate2DMake(30.691293,104.088264);  
  5. if (SYSTEM_VERSION_LESS_THAN(@"6.0"))// ios6以下,调用google map  
  6. {  
  7.     NSString *urlString = [[NSString alloc]  
  8.                            initWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirfl=d",  
  9.                            coords1.latitude,coords1.longitude,coords2.latitude,coords2.longitude];  
  10.     NSURL *aURL = [NSURL URLWithString:urlString];  
  11.     //打开网页google地图  
  12.     [[UIApplication sharedApplication] openURL:aURL];  
  13. }else// 直接调用ios自己带的apple map  
  14. {  
  15.     //当前的位置  
  16.     //MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];  
  17.     //起点  
  18.     MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords1 addressDictionary:nil]];  
  19.     //目的地的位置  
  20.     MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords2 addressDictionary:nil]];  
  21.     toLocation.name = @"目的地";  
  22.     NSArray *items = [NSArray arrayWithObjects:currentLocation, toLocation, nil];  
  23.       
  24.     /* 
  25.      //keys 
  26.      MKLaunchOptionsMapCenterKey:地图中心的坐标(NSValue) 
  27.      MKLaunchOptionsMapSpanKey:地图显示的范围(NSValue) 
  28.      MKLaunchOptionsShowsTrafficKey:是否显示交通信息(boolean NSNumber) 
  29.       
  30.      //MKLaunchOptionsDirectionsModeKey: 导航类型(NSString) 
  31.      { 
  32.         MKLaunchOptionsDirectionsModeDriving:驾车 
  33.         MKLaunchOptionsDirectionsModeWalking:步行 
  34.      } 
  35.       
  36.      //MKLaunchOptionsMapTypeKey:地图类型(NSNumber) 
  37.      enum { 
  38.      MKMapTypeStandard = 0, 
  39.      MKMapTypeSatellite, 
  40.      MKMapTypeHybrid 
  41.      }; 
  42.      */  
  43.     NSDictionary *options = @{  
  44.         MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,  
  45.         MKLaunchOptionsMapTypeKey:  
  46.     [NSNumber numberWithInteger:MKMapTypeStandard],  
  47.         MKLaunchOptionsShowsTrafficKey:@YES  
  48.     };  
  49.     //打开苹果自身地图应用,并呈现特定的item  
  50.     [MKMapItem openMapsWithItems:items launchOptions:options];  
  51. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值