【问题标题】:Google Maps not displaying for Android using Flutter谷歌地图不显示使用颤振的 Android
【发布时间】:2020-04-02 20:49:29
【问题描述】:

我正在尝试在我的屏幕上显示谷歌地图小部件。该小部件在 iOS 上完美运行(参见图 1),但在 Android 设备上仅显示谷歌徽标和灰屏(参见图 2),我无法识别问题。

我猜这是 API 密钥的问题,但是,我目前只是使用我创建的没有任何限制的公钥来尝试让某些东西正常工作。我已经正确配置了 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)

Android 清单:

    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>

飞镖地图小部件:

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

【问题讨论】:

  • 友情提示,我会删除您的 API 密钥并为其在 SO 上的帖子添加一个错误值,因此它不公开可用,因为您尚未对其进行保护。
  • @Jwildsmith 谢谢!

标签: android ios google-maps flutter api-key


【解决方案1】:

我会在评论中留下这个,但我还不能离开 cmets :) 你记得启用激活 android maps API 吗?

【讨论】:

    【解决方案2】:

    实际上我只是自己解决了这个问题,但是对于任何有相同或类似问题的人,我最终发现我使用模拟器下载的操作系统没有为其选择 Google API。查看下面的屏幕截图,其中突出显示了我添加的 SDK。希望这对其他人有帮助!

    Android SDK with Google API's under the "Show Package Details" Checked Box

    【讨论】:

      猜你喜欢
      • 2020-04-03
      • 2020-07-19
      • 1970-01-01
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      • 2013-06-13
      • 1970-01-01
      相关资源
      最近更新 更多