【问题标题】:Flutter marker appears but not map颤振标记出现但未映射
【发布时间】:2022-01-12 05:16:47
【问题描述】:

我正在使用颤振并尝试实现谷歌地图。

从图片中可以看出,标记渲染在正确的位置,它只是没有渲染实际的地图。此外,我试图让地址搜索栏自动完成,但也没有任何结果。您可以在下面的第二个块中查看此代码。

Expanded(
  child: GoogleMap(
    onMapCreated: _onMapCreated, initialCameraPosition:
      CameraPosition(
        target: _center,
        zoom: 11.0,
      ),
     markers: {
       Marker(markerId: MarkerId(searchField.text),
              position: _center)
     },
    ),
  )

我已经创建了一个 API 密钥,并将其放入我的应用程序中。我按照教程将其纳入其中,但仍然一无所获。

对于 iOS,我在我的 AppDelegate.swift 和地址搜索机制的 geomethods 中注册了它。我还在 Info.plist 中提示了位置权限。我有什么遗漏吗?

// geoMethods
final geoMethods = GeoMethods(
    googleApiKey: '(My API key was here, deleted for obvious reasons)',
    language: 'en',
    countryCode: 'us',
    countryCodes: ['us', 'es', 'co'],
    country: 'United States',
    city: 'New York',
  );

...
...
...

// Passed in for the search bar text field
onTap: () => showDialog(
  context: context,
  builder: (_) => AddressSearchBuilder.deft(
    geoMethods: geoMethods,
    controller: field,
    builder: AddressDialogBuilder(
      color: Color(0xFFE64225),
    ),
    onDone: (Address address) {
      print(address);
    },
  ),
)

【问题讨论】:

    标签: ios flutter google-cloud-platform


    【解决方案1】:

    检查一次您的 API 密钥。由于 API 密钥过期,某些时间地图无法加载。如果 googleApiKey 工作正常,请检查您的 AppDelegate.swift文件

    import UIKit
    import Flutter
    import GoogleMaps
    
    
    @UIApplicationMain
     @objc class AppDelegate: FlutterAppDelegate {
      override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
      ) -> Bool {
        GMSServices.provideAPIKey("your_ googleApiKey_here")
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-08
      • 2020-04-13
      • 2018-08-11
      • 2021-11-03
      • 1970-01-01
      • 2020-12-14
      • 2021-08-05
      • 1970-01-01
      相关资源
      最近更新 更多