Navigation-Use the system's own app navigation

Source: Internet
Author: User

Navigation:

    • You can navigate to the app that you want to have in your system by dropping the navigation position
    • Send a network request to a corporate server, get navigation data, draw your own navigation manually
    • Navigating with the three-party SDK (Baidu)

#import "ViewController.h"

#import <MapKit/MapKit.h>

#import "Mbprogresshud+mj.h"

@interface Viewcontroller ()

@property (Weak, nonatomic) Iboutlet Uitextfield *startfield;

@property (Weak, nonatomic) Iboutlet Uitextfield *endfield;

/**

* Coded Object

*/

@property (nonatomic, strong) Clgeocoder *geocoder;

@property (nonatomic, strong) Cllocationmanager *mgr;

@end

@implementation Viewcontroller

Lazy Loading

-(Clgeocoder *) geocoder{

if (!_geocoder) {

_geocoder = [[Clgeocoder alloc] init];

}

return _geocoder;

}

-(Cllocationmanager *) mgr{

if (!_mgr) {

_mgr = [[Cllocationmanager alloc] init];

}

return _mgr;

}

/**

* Start navigation

*/

-(Ibaction) STARTNAVBTN: (ID) Sender {

1. Gets the start and end point of the user input when the navigation is started

NSString *startstr = Self.startField.text;

NSString *endstr = Self.endField.text;

if (Startstr.length = = 0 | | startstr = = NIL | | endstr = NIL | endstr.length = = 0) {

[Mbprogresshud showerror:@ "Please enter the starting point and end point" toView:self.view];

Return

}

2. Geocoding with Geo objects to get to landmark objects (Clplacemark)

[Self.geocoder geocodeaddressstring:startstr completionhandler:^ (Nsarray *placemarks, NSError *error) {

if (Placemarks.count = = 0) return;

Start Location Landmark

Clplacemark *startplacemark = [Placemarks firstobject];

[Self.geocoder geocodeaddressstring:endstr completionhandler:^ (Nsarray *placemarks, NSError *error) {

if (Placemarks.count = = 0) return;

End Location Landmark

Clplacemark *endplacemark = [Placemarks firstobject];

3. Re-use the acquired landmark object (Clplacemark) to create (Mkpalcemark)-Start of item

[Self Startnavigationwithstartclplacemark:startplacemark endclplacemark:endplacemark];

}];

}];

}

/**

* Start navigation

*

* @param startclplacemark Start landmark

* @param Endclplacemark Terminal landmark

*/

-(void) Startnavigationwithstartclplacemark: (Clplacemark *) Startclplacemark Endclplacemark: (CLPlacemark *) Endclplacemark

{

0. Create a start and end point

0.1 creating a starting point landmark

Mkplacemark *startmark = [[Mkplacemark alloc] initwithplacemark:startclplacemark];

Mkmapitem *startitem = [[Mkmapitem alloc] initwithplacemark:startmark];

0.2 Creating a destination landmark

Mkplacemark *endmark = [[Mkplacemark alloc] initwithplacemark:endclplacemark];

Mkmapitem *enditem = [[Mkmapitem alloc] initwithplacemark:endmark];

Nsarray *items = @[startitem, Enditem];

/**

* Just call Mkmapitem's Open method, you can open the system's own map app to navigate

*

* @param nsarray tell system map app navigation route

*

* @launchOptions to start the system with the additional parameters of the app (navigation mode, whether it is necessary to show the bus situation, map mode ...)

*/

Nsmutabledictionary *mutdic = [Nsmutabledictionary dictionary];

Setting the mode of navigation-walking by car

Mutdic[mklaunchoptionsdirectionsmodekey] = mklaunchoptionsdirectionsmodedriving;

Set the map display mode

Mutdic[mklaunchoptionsmaptypekey] = @ (Mkmaptypehybrid);

[Mkmapitem Openmapswithitems:items Launchoptions:mutdic];

}

-(void) Viewdidload {

[Super Viewdidload];

//

if (IOS8) {

[Self.mgr requestalwaysauthorization];

}

}

Navigation-Use the system's own app 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.