Call System Map to navigate

Source: Internet
Author: User

The starting positions are Beijing, Shanghai, respectively. Effect

Customize two places, GeoCode, and navigate.

1 #import "MapViewController.h"2 #import<MapKit/MapKit.h>3 4 @interfaceMapviewcontroller ()5 6@property (nonatomic, strong) Clgeocoder *Geocoder;7 8 @end9 Ten @implementationMapviewcontroller One  A //Lazy Loading --(Clgeocoder *) Geocoder { -     if(!_geocoder) { the_geocoder =[[Clgeocoder alloc] init]; -     } -     return_geocoder; - } +  -- (void) Viewdidload { + [Super Viewdidload]; A[Self.geocoder geocodeaddressstring:@"Beijing"completionhandler:^ (Nsarray<clplacemark *> * _nullable placemarks, Nserror *_nullable Error) { atClplacemark *beginmark =[Placemarks firstobject]; -[Self.geocoder geocodeaddressstring:@"Shanghai"completionhandler:^ (Nsarray<clplacemark *> * _nullable placemarks, Nserror *_nullable Error) { -Clplacemark *endmark =[Placemarks firstobject]; -[Self Beginwithmarks: (Clplacemark *) Beginmark Andmark: (Clplacemark *) Endmark]; -              -         }]; in     }]; -    } to //implementation of custom navigation methods +- (void) Beginwithmarks: (Clplacemark *) Beginmark Andmark: (Clplacemark *) Endmark { -     //Create the array required for the Openmapswithitems method, because the object of the Clplacemark class is not created directly, so the object of the Clplacemark class is created indirectly using the Geocoding method above theMkplacemark *mkmarkb =[[Mkplacemark alloc] initwithplacemark:beginmark]; *Mkmapitem *begini =[[Mkmapitem alloc] initwithplacemark:mkmarkb]; $     Panax NotoginsengMkplacemark *MKMARKD =[[Mkplacemark alloc] initwithplacemark:endmark]; -Mkmapitem *endi =[[Mkmapitem alloc] initwithplacemark:mkmarkd]; the     //Start and End +Nsarray *array =@[begini,endi]; A     //the dictionary required to create the Openmapswithitems method theNsdictionary *dict = @{//Navigation mode + mklaunchoptionsdirectionsmodekey:mklaunchoptionsdirectionsmodedriving, -                            //Map Mode $ Mklaunchoptionsmaptypekey: @ (Mkmaptypehybrid), $                            //whether to show traffic - Mklaunchoptionsshowstraffickey: @ (YES) -                            }; the     //just remember the line method, push from bottom up, use what to create - [Mkmapitem Openmapswithitems:array launchoptions:dict];Wuyi } the  - @end

Call System Map to navigate

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.