【问题标题】:Flutter google map plugin is not working and not showing google mapFlutter 谷歌地图插件不工作,不显示谷歌地图
【发布时间】:2019-10-03 13:38:13
【问题描述】:

我正在尝试在我的应用中添加 Google 地图。我正在使用 google_maps_flutter 版本:0.5.21+7。我使用了来自 Google codelabs 的以下代码。这是代码

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  GoogleMapController mapController;

  final LatLng _center = const LatLng(45.521563, -122.677433);

  void _onMapCreated(GoogleMapController controller) {
    mapController = controller;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Maps Sample App'),
          backgroundColor: Colors.green[700],
        ),
        body: GoogleMap(
          onMapCreated: _onMapCreated,
          initialCameraPosition: CameraPosition(
            target: _center,
            zoom: 11.0,
          ),
        ),
      ),
    );
  }
}

但代码不起作用,地图没有显示。这是我在安卓模拟器上运行得到的错误报告,应用程序在真实设备上崩溃。

/        (23740): HostConnection::get() New Host Connection established 0xcba7f740, tid 23754
I/zzbz    (23740): Making Creator dynamically
W/mple.test_mapp(23740): Unsupported class loader
W/mple.test_mapp(23740): Skipping duplicate class check due to unsupported classloader
D/EGL_emulation(23740): eglMakeCurrent: 0xded8e8a0: ver 3 0 (tinfo 0xded203c0)
I/DynamiteModule(23740): Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:221
I/DynamiteModule(23740): Selected remote version of com.google.android.gms.maps_dynamite, version >= 221
V/DynamiteModule(23740): Dynamite loader version >= 2, using loadModule2NoCrashUtils
W/mple.test_mapp(23740): Unsupported class loader
W/mple.test_mapp(23740): Skipping duplicate class check due to unsupported classloader
I/Google Maps Android API(23740): Google Play services client version: 12451000
I/Google Maps Android API(23740): Google Play services package version: 19275040
W/mple.test_mapp(23740): Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
E/GoogleMapController(23740): Cannot enable MyLocation layer as location permissions are not granted
I/mple.test_mapp(23740): Background concurrent copying GC freed 7812(1108KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 1783KB/3MB, paused 5.572ms total 32.898ms
D/        (23740): HostConnection::get() New Host Connection established 0xc05b5f40, tid 23799
D/EGL_emulation(23740): eglCreateContext: 0xbf4da240: maj 1 min 0 rcv 1
D/EGL_emulation(23740): eglMakeCurrent: 0xe0785600: ver 3 0 (tinfo 0xc807bd60)
D/EGL_emulation(23740): eglMakeCurrent: 0xbf4da240: ver 1 0 (tinfo 0xbf4c6160)
D/EGL_emulation(23740): eglMakeCurrent: 0xe0785600: ver 3 0 (tinfo 0xc807bd60)
D/        (23740): HostConnection::get() New Host Connection established 0xc05d0700, tid 23752
E/Google Maps Android API(23740): Authorization failure.  Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map.
E/Google Maps Android API(23740): In the Google Developer Console (https://console.developers.google.com)
E/Google Maps Android API(23740): Ensure that the "Google Maps Android API v2" is enabled.
E/Google Maps Android API(23740): Ensure that the following Android Key exists:
E/Google Maps Android API(23740):   Android Application (<cert_fingerprint>;<package_name>): 0E:5D:3B:4B:C1:50:A0:16:C4:FF:FB:C1:2B:C1:AC:D3:15:25:D3:F6;com.example.test_mapp2
D/EGL_emulation(23740): eglMakeCurrent: 0xe0785600: ver 3 0 (tinfo 0xc807bd60)
D/EGL_emulation(23740): eglMakeCurrent: 0xe0785600: ver 3 0 (tinfo 0xc807bd60)
W/DynamiteModule(23740): Local module descriptor class for com.google.android.gms.googlecertificates not found.
I/DynamiteModule(23740): Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
I/DynamiteModule(23740): Selected remote version of com.google.android.gms.googlecertificates, version >= 4
W/mple.test_mapp(23740): Unsupported class loader
W/mple.test_mapp(23740): Skipping duplicate class check due to unsupported classloader

【问题讨论】:

  • 我认为日志中显示的 API 密钥是敏感信息。您可能需要编辑它。
  • 您是否将 api 密钥作为元数据添加到 Manifestfile 中?
  • @Ggriffo 是的,我已经添加了。

标签: google-maps flutter


【解决方案1】:

从这个错误日志E/Google Maps Android API(23740): Authorization failure. Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map.你有一个API授权失败。

我将在下面留下一些关于如何解决此问题的链接: Maps Android API: Authorization failure SO answer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多