LoginSignup
0
1

More than 3 years have passed since last update.

緯度・経度を指定してGoogleMapアプリを起動する

Last updated at Posted at 2021-01-26

やりたいこと

指定の緯度・経度の場所を中心とした状態で、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

0
1
0

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
0
1