やりたいこと
指定の緯度・経度の場所を中心とした状態で、GoogleMapアプリを起動したい。
実装方法
Info.plistに以下のエントリを追加する。
これをやっておかないと、iOS10以降(iOS9だったかも?)以降ではアプリを開けない。
Info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>comgooglemaps</string>
</array>
GoogleMapアプリを開きたい場所で下記のコードを実行。
この例では、東経135度、北緯35度を中心として表示する。
zoomの値を変更すると、縮尺を変更できる。
OpenGoogleMapApp.swift
let url=URL(string: "comgooglemaps://?q=35.0000,135.0000&mapmode=standard&zoom=14")!
if UIApplication.shared.canOpenURL(comgooglemapsUrl) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
print("Google Map App is not installed.")
}
動作確認環境
Xcode: 12.2
Swift: 5.3.1
iOS: 14.2