简体   繁体   中英

How to launch google maps uri after url_launcher update?

I've update my flutter app packages including url_launcher package from 6.0.20 to 6.1.2 .

After the update a lot of Android users (API 30/31/32) report that they cannot launch navigation to a defined point (latitude and longitude) using Google Maps app due to an error:

Webpage not available. 

Webpage not available
The webpage at intent://maps.app.goo.gl/?
link=https://www.google.com/maps/dir//45.8597077,.........
could not be loaded because:
net: ERR_UNKNOWN_URL_SCHEME

This is my working code with 6.0.20

final String gMapsUrl = 'https://www.google.com/maps/dir/api=1&destination=$latitude,$longitude&travelmode=driving';

if (Platform.isAndroid && await canLaunch(gMapsUrl)) {
  await launch(gMapsUrl);
}

and this is the not working one with 6.1.2

 final String gMapsUrl = 'https://www.google.com/maps/dir/api=1&destination=$latitude,$longitude&travelmode=driving';

if (Platform.isAndroid && await canLaunchUrl(gMapsUri)) {
  await launchUrl(gMapsUri);
} 

Which is now the correct way to launch a Google Maps url in order to launch inApp or web browser navigation without forcing user to use inApp or Web navigation?

[✓] Flutter (Channel stable, 2.10.3, on macOS 12.4 21F79 darwin-x64, locale en-IT)
    • Flutter version 2.10.3 at /Users/enrico/SDKs/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (3 months ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/enrico/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] VS Code (version 1.67.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (2 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 12 (API 32) (emulator)
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 101.0.4951.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Declare that the application wants to open URLs.

<!-- Place inside the <queries> element. -->
<intent>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="https" />
</intent>

Probably some defaults has been changed between these two version. Now specifying mode I solved my problem forcing opening on an app:

await launchUrl(gMapsUri, mode: LaunchMode.externalApplication);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM