Map-05. Navigation

Source: Internet
Author: User

Map-05. Navigation

The previous section talked about the pin's knowledge, this section is about navigation, this is very simple

Step: 1. Get the address entered by the user

2. Create a point at the destination on the map

3. Create a point on the map at the current location

4. Call the system's own map app navigation

Pre-code preparation:

Drag in three controls and take off line to VIEWCONTROLLER.M

Then on the code:

1 //2 //VIEWCONTROLLER.M3 //05. Navigation4 //5 //Created by admin on 16/5/31.6 //copyright©2016 year KXZDJ. All rights reserved.7 //8 9 #import "ViewController.h"Ten //Import Header File One #import<MapKit/MapKit.h> A  - @interfaceViewcontroller () -@property (Weak, nonatomic) Iboutlet Uitextfield *destinationfiled; the  - @end -  - @implementationViewcontroller +-(Ibaction) Navigation: (ID) Sender { -      +     //1. Get the location of user input ANSString *address =Self.destinationFiled.text; at     //Judging -     if(Address.length = =0) { -NSLog (@"Please enter your destination"); -         return; -     } -      in     //2. Create a point at the destination on the map -Clgeocoder *geo =[[Clgeocoder alloc] init]; to      +     //geo-coding -[Geo Geocodeaddressstring:address completionhandler:^ (Nsarray<clplacemark *> * _nullable placemarks, NSError *_nullable Error) { the          *         if(Placemarks.count = =0||error) { $NSLog (@"Geocoding failed");Panax Notoginseng             return ; -         } the         //get to an element in Placemarks (this may return multiple landmarks, but we'll just grab one, the point is not here) +Clplacemark *CLP =[Placemarks lastobject]; A          the         //This requires a clplacemark parameter, then this parameter is used in the previous geocoding, the same creation, but the need for geocoding in order to get to Placemarks?? +Mkplacemark *MKP =[[Mkplacemark alloc] INITWITHPLACEMARK:CLP]; -         //Create a user's point on the map using the following method, we need a mkplacemark parameter, we create a?? $Mkmapitem *destinationitem =[[Mkmapitem alloc] INITWITHPLACEMARK:MKP]; $          -         //3. Create a user's point on the map (a class method of Mkmapitem, get a point from the current location) -Mkmapitem *currentitem =[Mkmapitem mapitemforcurrentlocation]; the          -         //4. Call the system's own map app to navigateWuyi          the         //mkmaptypestandard = 0, Standard map -         //mkmaptypesatellite, satellite map Wu         //Mkmaptypehybrid Mixed Map -         //Mklaunchoptionsdirectionsmodekey: How to travel mklaunchoptionsmaptypekey: Map type Mklaunchoptionsshowstraffickey: Traffic information (no Clear Command + Left/stand-alone touch panel click to see AboutNsdictionary *option = @{mklaunchoptionsdirectionsmodekey:mklaunchoptionsdirectionsmodedriving, mklaunchoptionsmaptypekey:@0, Mklaunchoptionsshowstraffickey: @YES}; $          - [Mkmapitem Openmapswithitems:@[currentitem,destinationitem] launchoptions:option]; -          -          A     }]; +      the      -      $      the}

In the above code, there are several parameters that have not been used before, and there are illustrations below:

This is Mkmapitem, which is used to get users and destinations on the map point

This is the way to call the system's own map

Where are we going to find this dictionary?

Command + Left/Click Trackpad to click Mkmapitem:

There are already three marks in this one.

Mklaunchoptionsmaptypekey the value of this key in:

Mklaunchoptionsshowstraffickey the value of this key is of type Boolean

Above is a call system to bring the map to navigate the simple implementation, if there is insufficient, please advise.

Map-05. Navigation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.