iOS 坐标导航简单实现

简单的实现,从一点到iOS模拟器上设置的自己位置坐标的导航

1>反地理编码

2>导航

 

 

#import "ViewController.h"
#import <MapKit/MapKit.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置经纬度
    CLLocation *loc = [[CLLocation alloc] initWithLatitude:23.08 longitude:113.15];
    
    // 反地理编码
    CLGeocoder *coder = [[CLGeocoder alloc] init];
    [coder reverseGeocodeLocation:loc completionHandler:^(NSArray *placemarks, NSError *error) {
        
        if (error || 0 == placemarks.count) return ;
        CLPlacemark *place = [placemarks lastObject];
        
        MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:place];
        
        // 设置地图的起始位置
        MKMapItem *desc = [[MKMapItem alloc] initWithPlacemark:placemark];
        MKMapItem *source = [MKMapItem mapItemForCurrentLocation];
        
        NSArray *array = @[source, desc];
        
//            MK_EXTERN NSString * const MKLaunchOptionsDirectionsModeKey
//            MK_EXTERN NSString * const MKLaunchOptionsMapTypeKey
//            MK_EXTERN NSString * const MKLaunchOptionsShowsTrafficKey
        
    NSDictionary *dict = @{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
                          // 导航方式 (开车 步行..)
                           MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard),
                          // 标准地图(卫星地图,混合)
                           MKLaunchOptionsShowsTrafficKey : @YES
                           // 是否显示交通状况
                           };
    
    // 打开系统地图,开始导航
    [MKMapItem openMapsWithItems:array launchOptions:dict];
    }];
    
}

@end

 

posted @ 2015-08-03 21:29  流星飞雪shmily  阅读(290)  评论(0编辑  收藏  举报