• 主页
  • 系列总集
  • OpenCV
  • CMake
  • iOS
  • Java
  • 前端
所有文章 关于我

  • 主页
  • 系列总集
  • OpenCV
  • CMake
  • iOS
  • Java
  • 前端

MKMapKit(五):调用自带地图导航

2017-03-07

调用苹果地图导航

调用苹果自带地图导航的相关类叫 MapItem,导航的英文不叫Navigation而是叫Direction,相关官方文档为Asking the Maps App to Display Directions

MapItem

调用方法

MapItem一共有两个方法

方法名 作用
+ openMapsWithItems:launchOptions: 跳转到自带地图并且打开一组Item
- openInMapsWithLaunchOptions: 跳转到自带地图,打开这个Item

Options

可以看到两个方法都提到了Options,具体的Options包括以下

| Option | 取值 | 可选项 |
| :————- | :————- |
| MKLaunchOptionsDirectionsModeKey | 导航方式,有四个选项,比如步行还是开车官方文档 | MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsDirectionsModeWalking,MKLaunchOptionsDirectionsModeTransit,MKLaunchOptionsDirectionsModeDefault |
| MKLaunchOptionsMapTypeKey | 地图模式,采用NSNumber | 对应MKMapType的枚举 |
| MKLaunchOptionsMapCenterKey | NSValue | 把Coordinate编码成NSValue |
| MKLaunchOptionsMapSpanKey | NSValue | MKCoordinateSpan编码成NSValue |
| MKLaunchOptionsShowsTrafficKey | 交通状况,BOOL值 | 0 1 |
| MKLaunchOptionsCameraKey | 一个Object | MKMapCamera的实例 |

placeMark

是MapItem的一个对象,包含了基本信息例如电话、URL等等,用于实例化MapItem,本身可以通过 initWithCoordinate: 实例化

实例化方法

实例化 备注
+ mapItemForCurrentLocation 返回当前设备的MapItem,是一个单例
- initWithPlacemark: 通过PlaceMark进行实例化

示例代码

从当前位置导航到某个目的地

1
2
3
4
5
6
CLLocationCoordinate2D drone = _mapKit.drone.coordinate;
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:drone]]; //目的地坐标
toLocation.name = @"目的地"; //目的地名字
[MKMapItem openMapsWithItems:@[currentLocation, toLocation] launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:NO]}];

赏

请问老板还招人么(/ω\)

支付宝
微信
  • iOS
  • MKMapKit
  • Tutorial

扫一扫,分享到微信

微信分享二维码
MKMapKit(六):指南针模式
MKMapKit(四):拦截地图的操作手势
© 2021 Alan Li
Hexo Theme Yilia by Litten
  • 所有文章
  • 关于我

tag:

  • iOS
  • Java
  • Collection
  • Python
  • Shell
  • CMake
  • Memory
  • JavaScript
  • Architecture
  • AnchorPoint
  • Android
  • Web
  • Annotation
  • AFNetworking
  • Window
  • ViewController
  • AutoLayout
  • Dozer
  • CoreAnimation
  • Cycle Retain
  • Block
  • UI
  • IDE
  • FrontEnd
  • CSS
  • Category
  • TableViewCell
  • Security
  • Net
  • JSP
  • Spring
  • C
  • MyBatis
  • Date
  • React
  • GCD
  • UITouch
  • Gesture
  • UIControl
  • Git
  • HTML
  • HTTPS
  • HTTP
  • Servlet
  • Server
  • DataBase
  • MySQL
  • Linux
  • Tutorial
  • Ajax
  • Type
  • JQuery
  • JSON
  • Exception
  • Parameter
  • Reflect
  • Thread
  • Sort
  • KVO
  • MKMapKit
  • Overlay
  • Maven
  • Configure
  • Tips
  • Transaction
  • Swift
  • NavigationBar
  • Nginx
  • Runtime
  • OpenCV
  • Property
  • Playground
  • Protocol
  • Redux
  • ScrollView
  • Session
  • Cookie
  • Shiro
  • Error
  • Singleton
  • RegEx
  • StackView
  • StatusBar
  • Base64
  • Socket
  • TCP
  • IP
  • TextField
  • CALayer
  • UILabel
  • View
  • Animation
  • Xcode
  • Hexo
  • Terminal
  • OC
  • Device
  • Log
  • Image
  • JUnit
  • Oval
  • Archive
  • XSS
  • Compiler
  • Aspect
  • Responder
  • Class
  • FireWall
  • RetainCount
  • Const
  • Frame
  • String
  • Symbols
  • Framework
  • CocoaPods
  • Unity
  • Message
  • Button
  • AuthorizationStatus
  • Struct
  • XCTest
  • NSNotification
  • Contact

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

我写的,大概率是错的。。。。。