ectionsModeKey: MKLaunchOptionsDirectionsModeDriving as AnyObject,
// 地图样式:标准样式
MKLaunchOptionsMapTypeKey: MKMapType.standard.rawValue as AnyObject,
// 显示交通:显示
MKLaunchOptionsShowsTrafficKey: true as AnyObject
]
// 根据 MKMapItem 的起点和终点组成数组, 通过导航地图启动项参数字典, 调用系统的地图APP进行导航
MKMapItem.openMaps(with: mapItems, launchOptions: dic)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
运行效果:
2.2 使用手动画线导航
步骤2的方法:
步骤4的代理方法:
代码17:使用手动画线导航 Demo
编译环境:Xcode 8.0
模拟器版本:iOS 10
Swift版本:3.0
【OC 语言】
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface ViewController ()<MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (nonatomic, strong) CLGeocoder *geoCoder;
@end
@implementation ViewController
-(CLGeocoder *)geoCoder{
if (!_geoCoder) {
_geoCoder = [[CLGeocoder alloc] init];
}
return _geoCoder;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView.delegate = self;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
// 导航包括:起点和终点 数据由苹果处理
[self.geoCoder geocodeAddressString:@"广州" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
// 1. 拿到广州地标对象
CLPlacemark *gzP = [placemarks firstObject];
// 1.2 创建圆形的覆盖层数据模型
MKCircle *circle1 = [MKCircle circleWithCenterCoordinate:gzP.location.coordinate
radius:100000];
// 1.3 添加覆盖层数据模型到地图上
[self.mapView addOverlay:circle1];
[self.geoCoder geocodeAddressString:@"上海" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
// 2. 拿到上海地标对象
CLPlacemark *shP = [placemarks firstObject];
// 2.2 创建圆形的覆盖层数据模型
MKCircle *circle2 = [MKCircle circleWithCenterCoordinate:shP.location.coordinate