设为首页 加入收藏

TOP

【iOS】7.4 定位服务->3.2 地图框架MapKit 功能2:路线规划(导航)(三)
2017-10-11 18:36:24 】 浏览:5101
Tags:iOS 7.4定位 服务 -> 3.2 地图 框架 MapKit 功能 路线 规划 导航
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
                                                     
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 3/8/8
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【代码笔记】iOS-cell自动变化大小 下一篇iOS scene之间的跳转类型——Segue

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目