• ios调用系统导航


    #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

  • 相关阅读:
    转:Java 6 JVM参数选项大全(中文版)
    转:Http Get Post put delete
    转:Google MapReduce中文版
    转:java.net.SocketException: Too many open files解决方法
    转:UML类图基础
    转:Maven常用命令
    转:ibatis配置简介
    转:导出 Oracle 数据库中所所有用户表的表结构
    C# 中使用iTextSharp组件修改PDF元数据(title,Keywords等)
    SQL Server跨服务器查询
  • 原文地址:https://www.cnblogs.com/tangranyang/p/4655802.html
Copyright © 2020-2023  润新知