IOS 8 使用系統內建導航

來源:互聯網
上載者:User

標籤:

////  ViewController.m//  APP內建導航////  Created by wup on 15/5/23.//  Copyright (c) 2015年 apple. All rights reserved.//#import "ViewController.h"#import <MapKit/MapKit.h>@interface ViewController ()@property (nonatomic,strong)  CLGeocoder *geo;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.//    CLLocationManager *clmgr = [[CLLocationManager alloc] init];//    [clmgr requestAlwaysAuthorization];    //    MKMapView *mv = [[MKMapView alloc] initWithFrame:self.view.bounds];//    [self.view addSubview:mv];    [self.geo  geocodeAddressString:@"麗江" completionHandler:^(NSArray *placemarks, NSError *error) {                             //擷取到起點的MKplaceMark                MKPlacemark *startPlace = [[MKPlacemark alloc] initWithPlacemark:[placemarks firstObject]];                //等待擷取到起點的placemarks之後在擷取終點的placemarks,block回調延遲問題        [self.geo  geocodeAddressString:@"北京" completionHandler:^(NSArray *placemarks, NSError *error) {                        /**              擷取到終點的MKplaceMark,MKPlaceMark 是ClPlaceMark的子類。             */            MKPlacemark *endPlace = [[MKPlacemark alloc] initWithPlacemark:[placemarks firstObject]];                        /**             將MKPlaceMark轉換成MKMapItem,這樣可以放入到item這個數組中              */            MKMapItem *startItem = [[MKMapItem alloc ] initWithPlacemark:startPlace];            MKMapItem *endItem = [[MKMapItem alloc ] initWithPlacemark:endPlace];                        NSArray *item = @[startItem ,endItem];                        //建立字典儲存導航的相關參數            NSMutableDictionary *md = [NSMutableDictionary dictionary];            md[MKLaunchOptionsDirectionsModeKey] = MKLaunchOptionsDirectionsModeDriving;            md[MKLaunchOptionsMapTypeKey] = [NSNumber numberWithInteger:MKMapTypeHybrid];                                                            /**             *調用app內建導航,需要傳入一個數組和一個字典,數組中放入MKMapItem,             字典中放入對應索引值                          MKLaunchOptionsDirectionsModeKey   開啟導航模式             MKLaunchOptionsMapTypeKey  地圖模式                                                 MKMapTypeStandard = 0,                                                 MKMapTypeSatellite,                                                 MKMapTypeHybrid                          // 導航模式             MKLaunchOptionsDirectionsModeDriving 開車;             MKLaunchOptionsDirectionsModeWalking 步行;             */#warning 其實所有的代碼都是為了下面一句話,開啟系統內建的高德地圖然後執行某些動作,launchOptions裡面的參數指定做哪些動作            [MKMapItem openMapsWithItems:item launchOptions:md];        }];    }]; }#pragma mark - 超級懶載入-(CLGeocoder *)geo{    if (!_geo)    {        _geo = [[CLGeocoder alloc] init];            }    return  _geo;}@end








IOS 8 使用系統內建導航

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.