0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

FlutterでGoogleMapアプリを開く

Posted at

Flutterにおいて、url_laucherを使用してGoogleMapのUrl(https://www.google.com/maps) を立ち上げた場合、
どう表示するかはOSがよしなに対応してくれるので、動作が予測できない部分があります。
(GoogleMapアプリが立ち上がる or 開発アプリ内でgoogleMapのwebサイトにアクセスする、など)

地図に関してはアプリで閲覧したいユーザーが多いと思われるので、明示的にアプリを開きたいところです。
GoogleMapを含めた地図アプリの内、利用可能なアプリをに開くコードを示します。

map_app_launcher.dart
final googleMapAppUurl = Uri.parse('comgooglemaps://q=$address');
final appleMapAppUrl   = Uri.parse('https://maps.apple.com/?q=$address');

if (await canLaunchUrl(googleMapAppUurl)) { // GoogleMapアプリは立ち上げられるか
  // GoogleMapアプリを立ち上げる
  await launchUrl(googleMapAppUurl);
} else if (await canLaunchUrl(appleMapAppUrl)) { // iOSの地図アプリは立ち上げられるか
  // iOSの地図アプリを立ち上げる
  await launchUrl(appleMapAppUrl);
} else {
  throw 'Could not launch url';
}

参考:https://naipaka.hatenablog.com/entry/2021/08/05/091411
参考:https://itecnote.com/tecnote/r-open-google-maps-app-if-available-with-flutter/

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?