//
// ViewController.m
// 自带地图应用 路径导航
//
// Created by DC017 on 15/12/24.
// Copyright © 2015年 DC017. All rights reserved.
//
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface ViewController ()
{
CLGeocoder * geocoder;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
geocoder=[[CLGeocoder alloc]init];
[self drawRoute];
}
-(void)drawRoute{
//根据“西安”进行地理编码
[geocoder geocodeAddressString:@"西安市" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
CLPlacemark * placemark1=[placemarks firstObject];
//定位地标,转化为地图地标
MKPlacemark * mkditu1=[[MKPlacemark alloc]initWithPlacemark:placemark1];
//注意:地理编码一次只能定位一个位置
[geocoder geocodeAddressString:@"新疆" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
CLPlacemark * placemark2=[placemarks firstObject];
MKPlacemark * mkditu2=[[MKPlacemark alloc]initWithPlacemark:placemark2];
//配置地图信息位置
NSDictionary * dic=@{
MKLaunchOptionsMapTypeKey:@(MKMapTypeStandard),
MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving
};
//将地标转化成地图上的点
MKMapItem * mapItem1=[[MKMapItem alloc]initWithPlacemark:mkditu1];
MKMapItem * mapItem2=[[MKMapItem alloc]initWithPlacemark:mkditu2];
//加载地图 (点,设置的选项)
[MKMapItem openMapsWithItems:@[mapItem1,mapItem2] launchOptions:dic];
}];
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end