url_launcher更新后,如何启动Google Maps URI?

发布于 2025-01-31 07:45:21 字数 2318 浏览 3 评论 0原文

我已经更新了我的Flutter App软件包,包括url_launcher 6.0.20的软件包 6.1.2

更新后,许多Android用户(API 30/31/32)报告说,由于错误,他们无法使用Google Map App启动导航(纬度和经度),

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

这是我的工作代码:我使用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);
}

,这是与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);
} 

它现在是启动Google Maps URL的正确方法,以启动InApp或Web浏览器导航而无需强迫用户使用Inapp还是Web导航?

[✓] 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:
      
              

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑叹一世浮沉 2025-02-07 07:45:21

这两个版本之间可能已经更改了一些默认值。
现在指定模式我解决了我的问题强迫在应用程序上打开:

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

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);
娜些时光,永不杰束 2025-02-07 07:45:21

声明该应用程序要打开URL。

<!-- 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文