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