几天前,谷歌地图和苹果地图都完美地启动了。我在主频道上将 Flutter 更新到最新版本到 1.13.1。我假设更新后它停止工作。所以我将频道更改为测试版并尝试了,但仍然不起作用。尝试启动谷歌地图或苹果地图时,IOS应用程序崩溃,我既不理解错误,也没有在互联网上找到一些东西。
任何帮助都非常感谢。
我的用户界面代码:
ListTile(
title: Text("Launch Google Maps", textAlign: TextAlign.center),
onTap: () async {
final String clubName =
clubs[index].name.toString().replaceAll(" ", "+");
print("Name: $clubName"); // 'Flawless+Club'
final String clubCity = clubs[index].stadt;
print("Name: $clubCity"); // 'London'
final String newGoogleUrl =
"https://www.google.com/maps/dir/?api=1&destination=$clubName+$clubCity";
if (await canLaunch(newGoogleUrl)) {
await launch(newGoogleUrl);
} else {
throw 'Could not launch $newGoogleUrl';
}
},
),
颤振医生 -v 输出:
[✓] Flutter (Channel beta, v1.12.13+hotfix.3, on Mac OS X 10.15.1 19B88, locale en-DE)
• Flutter version 1.12.13+hotfix.3 at /Library/Flutter
• Framework revision 57f2df76d7 (2 days ago), 2019-12-05 21:23:21 -0800
• Engine revision ac9391978e
• Dart version 2.7.0
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/murat/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.2.1, Build version 11B500
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.4)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 35.3.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
[✓] VS Code (version 1.40.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.7.0
[✓] Connected device (1 available)
• No issues found!
点击列表磁贴时出错:
Lost connection to device.
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23c4f02e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50b97b20 objc_exception_throw + 48
2 Foundation 0x00007fff2578c55b -[__NSConcreteURLComponents initWithString:] + 0
3 CoreServices 0x00007fff24e970bd -[_LSURLOverride initWithOriginalURL:checkingForAvailableApplications:newsOnly:] + 151
4 CoreServices 0x00007fff24e97992 -[_LSURLOverride initWithOriginalURL:newsOnly:] + 25
5 CoreServices 0x00007fff24e982ae _ZN14LaunchServices12URLOverridesL20getURLOverrideCommonEP5NSURLb + 399
6 CoreServices 0x00007fff24e9810e -[LSApplicationWorkspace(LSURLOverride) URLOverrideForURL:] + 14
7 UIKitCore<…>
Exited (sigterm)
我遇到了同样的错误。 我的问题是我正在使用这个包含航点名称的 url。
'https://maps.apple.com/?q=' + '$name' + '&ll=$lat,$lon';
如果航点名称 ($name
( 包含空格,例如 "纽约"launch_url
不会将空格字符转换为 %20。
我通过使用name.toString().replaceAll(' ', "%20")
修复了它。 完整网址示例:https://maps.apple.com/?q=' + name.toString().replaceAll(' ', "%20") + '&ll=$lat,$lon'
根据我的经验,onTap
不能很好地使用async
关键字。我会将逻辑提取到另一种方法中。build
方法甚至不应该包含逻辑,它们应该仅用于 UI,因为它们应该运行起来很便宜,并且可以随时出于任何原因调用。
onTap: () => myFunction(clubs, index),
// the function
void myFunction(var clubs, int index) async {
final String clubName = clubs[index].name.toString().replaceAll(" ", "+");
print("Name: $clubName"); // 'Flawless+Club'
final String clubCity = clubs[index].stadt;
print("Name: $clubCity"); // 'London'
final String newGoogleUrl = "https://www.google.com/maps/dir/?api=1&destination=$clubName+$clubCity";
if (await canLaunch(newGoogleUrl)) {
await launch(newGoogleUrl);
} else {
throw 'Could not launch $newGoogleUrl';
}
}
问题已解决。
我在我的club[index].stadt
里有一个城市列表,一个变音符号为"ä,ö,ü"的城市。
通过添加
final String clubCity = clubs[index].stadt.toString().replaceAll("ü", "ue");
它解决了这个问题。因为,每当在 url 中调用带有变音符号的城市时,它都会使应用程序崩溃!
天哪,这花了我好久!
我有完全相同的症状,但我的问题出在URL&waypoints=
部分。显然,安卓将能够消化以下URL(示例(:
https://www.google.com/maps/dir/?api=1&origin=1.11,-0.123&destination=2.22,-0.456&waypoints=1.11,-0.123|1.67,-0.245|2.22,-0.456&travelmode=driving&dir_action=navigate
而对于 ios 版本,我必须将waypoints
中的|
符号显式转换为%7C
,因此它看起来像这样:
https://www.google.com/maps/dir/?api=1&origin=1.11,-0.123&destination=2.22,-0.456&waypoints=1.11,-0.123%7C1.67,-0.245%7C2.22,-0.456&travelmode=driving&dir_action=navigate