我正在尝试在我的屏幕上显示谷歌地图小部件。该小部件在 iOS 上完美运行(参见图 1),但在 Android 设备上仅显示谷歌 Logo 和灰屏(参见图 2),我无法识别问题。
我猜这是 API key 的问题,但是,我目前只是使用我创建的没有任何限制的公钥,只是为了尝试让某些东西正常工作。我已经正确配置了 android manifest
图1:
Working iOS output
图 2:
Not working Android output
调试输出:
✓ Built build/app/outputs/apk/debug/app-debug.apk.
D/FlutterActivity(31362): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate(31362): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate(31362): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate(31362): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView(31362): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@f81b727
D/FlutterActivityAndFragmentDelegate(31362): Executing Dart entrypoint: main, and sending initial route: /
D/EGL_emulation(31362): eglMakeCurrent: 0xcfd1a5a0: ver 3 0 (tinfo 0xb8ce7e40)
W/Gralloc4(31362): allocator 3.x is not supported
W/Gralloc3(31362): allocator 3.x is not supported
I/zzbz (31362): Making Creator dynamically
W/s_app_prototyp(31362): Unsupported class loader
I/DynamiteModule(31362): Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:222
I/DynamiteModule(31362): Selected remote version of com.google.android.gms.maps_dynamite, version >= 222
V/DynamiteModule(31362): Dynamite loader version >= 2, using loadModule2NoCrashUtils
I/Google Maps Android API(31362): Google Play services client version: 12451000
I/Google Maps Android API(31362): Google Play services package version: 200616040
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->allocateInstance(Ljava/lang/Class;)Ljava/lang/Object; (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->peekLong(JZ)J (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->pokeLong(JJZ)V (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->pokeInt(JIZ)V (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->peekInt(JZ)I (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->pokeByte(JB)V (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->peekByte(J)B (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->pokeByteArray(J[BII)V (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Llibcore/io/Memory;->peekByteArray(J[BII)V (greylist, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->arrayBaseOffset(Ljava/lang/Class;)I (greylist,core-platform-api, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->arrayIndexScale(Ljava/lang/Class;)I (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/s_app_prototyp(31362): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
W/s_app_prototyp(31362): Accessing hidden field Ljava/nio/Buffer;->address:J (greylist, reflection, allowed)
安卓 list :
package="com.example.ms_app_prototype">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="ms_app_prototype"
android:icon="@mipmap/ic_launcher">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="inserted correct value"/>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
飞镖 map 小部件:
import 'package:google_maps_flutter/google_maps_flutter.dart';
class Map extends StatelessWidget {
GoogleMapController mapController;
final LatLng _center = const LatLng(33.509186, -112.020682);
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}
@override
Widget build(BuildContext context) {
return Container(
child: GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 15.0,
),
),
);
}
}
最佳答案
我会在评论中留下这个,但我还不能发表评论:) 你确实记得启用激活 android maps API 吗?
关于android - 谷歌地图不显示使用 flutter 的 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61000876/