Navigate---by Zhang Xiuqing using the system app

Source: Internet
Author: User

The Apple system itself comes with a map app, but the function is not very powerful, but some simple navigation functions can be done, the following paste my code

////VIEWCONTROLLER.M//System App Navigation////Created by Zhang Xiuqing on 15/5/4.//Copyright (c) 2015 Zhang Xiuqing. All rights reserved.//#import "ViewController.h"#import<MapKit/MapKit.h>@interfaceViewcontroller ()/** * Input starting point*/@property (nonatomic,strong) Uitextfield*Starttf;/** * Enter the end point*/@property (nonatomic,strong) Uitextfield*ENDTF;/** * Start navigation button*/@property (nonatomic,strong) UIButton*Navigatebutton;/** * Geo encoder*/@property (nonatomic,strong) Clgeocoder*Geocoder;@end@implementationViewcontroller#pragmaMark-Lazy Loading-(Clgeocoder *) geocoder{if(!_geocoder) {_geocoder=[[Clgeocoder alloc]init]; }    return_geocoder;}- (void) viewdidload {[Super viewdidload]; [Self initui];}#pragmaMark-Initialize ui-(void) initui{_starttf= [[Uitextfield alloc]initwithframe:cgrectmake ( -, -, Max, -)]; _starttf.borderstyle=Uitextborderstyleroundedrect; _starttf.placeholder=@"begin";        [Self.view Addsubview:_starttf]; _ENDTF= [[Uitextfield alloc]initwithframe:cgrectmake ( -, Max, Max, -)]; _endtf.borderstyle=Uitextborderstyleroundedrect; _endtf.placeholder=@"End";        [Self.view ADDSUBVIEW:_ENDTF]; _navigatebutton=[UIButton Buttonwithtype:uibuttontypesystem]; _navigatebutton.frame= CGRectMake ( -, $, -, -); [_navigatebutton settitle:@"Start"Forstate:uicontrolstatenormal];    [_navigatebutton addtarget:self Action: @selector (Startnavigation) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:_navigatebutton];}#pragmaMark-Start Navigation-(void) startnavigation{[Self.geocoder geocodeAddressString:self.startTF.text Completionhandler:^ (Nsarray *placemarks, Nserror *error) {               /** * Get initial location information*/        if(Placemarks.count = =0) {            return ; } Clplacemark*startclplacemark =[Placemarks Lastobject]; [Self.geocoder geocodeAddressString:self.endTF.text Completionhandler:^ (Nsarray *placemarks, Nserror *error) {            /** * Get the end location information*/            if(Placemarks.count = =0) {                return ; } Clplacemark*endclplacemark =[Placemarks Lastobject]; //Start Navigation[self Navigatewithstartclplacemark:startclplacemark endclplacemark:endclplacemark];            }]; }];}//Start Navigation-(void) Navigatewithstartclplacemark: (Clplacemark *) Startclplacemark Endclplacemark: (Clplacemark *) endclplacemark{Mkplacemark*startmkplacemark =[[Mkplacemark Alloc]initwithplacemark:startclplacemark]; Mkplacemark*endmkplacemark =[[Mkplacemark Alloc]initwithplacemark:endclplacemark]; Mkmapitem*startitem =[[Mkmapitem Alloc]initwithplacemark:startmkplacemark]; Mkmapitem*enditem =[[Mkmapitem Alloc]initwithplacemark:endmkplacemark]; Nsmutabledictionary*dict =[Nsmutabledictionary dictionary]; Dict[mklaunchoptionsmaptypekey]= @ (Mkmaptypestandard);//Map ModeDict[mklaunchoptionsdirectionsmodekey] = mklaunchoptionsdirectionsmodedriving;//navigation mode (walk/drive)[Mkmapitem Openmapswithitems:@[startitem,enditem] launchoptions:dict];//Open System map start navigation}@end

Navigate---by Zhang Xiuqing using the system app

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.