【问题标题】:Flutter Google Map Crashes on first open in IOSFlutter Google Map 在 IOS 中首次打开时崩溃
【发布时间】:2020-02-28 20:54:03
【问题描述】:

在启动屏幕之后,我的应用程序的第一页上有一个谷歌地图。 当我第一次运行该应用程序和一个非常新的版本时,它在 IOS 上崩溃并出现以下错误:PlatformException(create_failed, can't create a view on a headless engine, null)

这是我的谷歌地图代码,只有第一次安装应用时才会在 IOS 中发生崩溃。

GoogleMap(
            myLocationEnabled: false,
            myLocationButtonEnabled: false,
            zoomGesturesEnabled: true,
            scrollGesturesEnabled: true,
            rotateGesturesEnabled: false,
            tiltGesturesEnabled: false,
            onMapCreated: _onMapCreated,
            initialCameraPosition: CameraPosition(
              target: _location,
              zoom: 12,
              /* tilt: 50.0,
                      bearing: 45.0,*/
            ),
            mapType: _currentMapType,
            markers: Set<Marker>.of(markers.values),
            onCameraMove: _onCameraMove,
            onCameraIdle: _onCameraIdle,
          )

我正在 GitHub 上跟进这个问题:https://github.com/flutter/flutter/issues/36310 但它没有适当的解决方案。 谁能帮我解决这个问题?

【问题讨论】:

  • 如果您仍然遇到此问题,您能否分享更多代码,例如您的脚手架以及支持功能,例如_onMapCreated

标签: google-maps flutter flutter-layout


【解决方案1】:

您是否在正确的位置正确注册了您的 API 密钥? 这需要在 Flutter 引擎启动之前在 appDelegate 类中注册。(请注意,这是一个 swift 文件)

import UIKit
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GMSServices.provideAPIKey("super_secret_api_key")
    GeneratedPluginRegistrant.register(with: self); 
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

【讨论】:

    猜你喜欢
    • 2014-11-06
    • 2023-03-18
    • 2021-11-19
    • 2019-03-03
    • 2019-06-28
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 2017-02-09
    相关资源
    最近更新 更多