码迷,mamicode.com
首页 > 移动开发 > 详细

ios调用系统导航

时间:2015-07-17 22:30:18      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

#import "ViewController.h"

#import <MapKit/MapKit.h>

 

@interface ViewController ()

@property(nonatomic,weak)UITextField*destination;

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    UITextField *field=[[UITextField alloc]init];

    field .frame=CGRectMake(10, 10, 100, 30);

    [field becomeFirstResponder];

    [self.view addSubview:field];

    self.destination=field;

    

    UIButton*btn= [UIButton buttonWithType:UIButtonTypeContactAdd];

    btn.frame=CGRectMake(120, 10, 50, 20);

    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btn];

    

}

-(void)btnClick

{

    CLGeocoder *geo=[[CLGeocoder alloc]init];

    [geo geocodeAddressString:self.destination.text completionHandler:^(NSArray *placemarks, NSError *error) {

        //地理编码后拿到地标

        CLPlacemark *pm=[placemarks firstObject];

        //创建MKPlacemark

        MKPlacemark *mkp=[[MKPlacemark alloc]initWithPlacemark:pm];

        //创建目的地对象

        MKMapItem *destination=[[MKMapItem alloc]initWithPlacemark:mkp];

        //获取用户当前的item

        MKMapItem *current=[MKMapItem mapItemForCurrentLocation];

        

        //2.开启导航//设置地图出行方式,设置地图类型,设置是否显示交通状况

        NSDictionary *operation=@{

                                  MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,

                                  MKLaunchOptionsMapTypeKey:@0,

                                  MKLaunchOptionsShowsTrafficKey:@NO};

        [MKMapItem openMapsWithItems:@[current,destination] launchOptions:operation];

    }];

    

}

 

 

 

@end

ios调用系统导航

标签:

原文地址:http://www.cnblogs.com/tangranyang/p/4655802.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!