iOS地图系统导航

前几天项目里面需要加导航,加百度导航吧,问题来了百度导航跟百度语音TTS冲突,没有办法,只好把用系统自带的地图导航。iOS9之后系统地图也可以退回到应用中。

1.设定出发地和目的地导航(传入的是地理位置)

#pragma mark - 跳转到系统导航
- (void)jumpToSystemNaviWithStart:(NSString *)start end:(NSString *)end {
    //根据出发地地理编码
    [_geocoder geocodeAddressString:start completionHandler:^(NSArray *placemarks, NSError *error) {
        CLPlacemark *clPlacemark1=[placemarks firstObject];//获取第一个地标
        MKPlacemark *mkPlacemark1=[[MKPlacemark alloc]initWithPlacemark:clPlacemark1];
        //注意地理编码一次只能定位到一个位置,不能同时定位,所在放到第一个位置定位完成回调函数中再次定位
        [_geocoder geocodeAddressString:end completionHandler:^(NSArray *placemarks, NSError *error) {
            CLPlacemark *clPlacemark2=[placemarks firstObject];//获取第一个地标
            MKPlacemark *mkPlacemark2=[[MKPlacemark alloc]initWithPlacemark:clPlacemark2];
            NSDictionary *options=@{MKLaunchOptionsMapTypeKey:@(MKMapTypeStandard),MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving};
            MKMapItem *mapItem1=[[MKMapItem alloc]initWithPlacemark:mkPlacemark1];
            MKMapItem *mapItem2=[[MKMapItem alloc]initWithPlacemark:mkPlacemark2];
            [MKMapItem openMapsWithItems:@[mapItem1,mapItem2] launchOptions:options];
        }];
    }];
}

2.根据自己当前位置导航到具体位置

#pragma mark - 默认位置导航
- (void)startNaviWith:(CLLocationCoordinate2D)coordinate2D locationName:(NSString *)name{
    MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
     MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coordinate2D addressDictionary:nil]];
     toLocation.name = name;
    NSArray *items = [NSArray arrayWithObjects:currentLocation, toLocation, nil];
    NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES };
     [MKMapItem openMapsWithItems:items launchOptions:options];
}

3.根据起始点坐标进行导航

#pragma mark - 使用地理坐标进行导航
- (void)startNaviFrom:(CLLocationCoordinate2D)start toDest:(CLLocationCoordinate2D)dest {
    NSDictionary *options=@{MKLaunchOptionsMapTypeKey:@(MKMapTypeStandard),MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving};
    MKMapItem *mapItem1=[[MKMapItem alloc]initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:start addressDictionary:nil]];
    MKMapItem *mapItem2=[[MKMapItem alloc]initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:dest addressDictionary:nil]];
    [MKMapItem openMapsWithItems:@[mapItem1,mapItem2] launchOptions:options];
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值