LoginSignup
4

More than 5 years have passed since last update.

Swift3で標準マップを開く(URLスキーム)

Last updated at Posted at 2016-11-16

実現したいこと

URLスキームで標準のマップアプリを開いて指定した、緯度経度への経路案内を行いたい。

開発環境

Xcode8.1
Swift3

実装方法

let latitude:String = "指定緯度"
let longitude:String = "指定経度"
let daddr = latitude + "," + longitude
let urlString = "http://maps.apple.com/?daddr=\(daddr)&dirflg=d"
let encodedUrl = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = NSURL(string: encodedUrl!)!
UIApplication.shared.openURL(url as URL)

daddrに行きたい場所の緯度と経度を渡して、dirflgに探索方法(車:dまたはdirflgなし,(デフォルト)電車:dirflg=r 徒歩:dirflg=w)を渡し、URLスキームでマップアプリで開く。

参照

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4