【问题标题】:How to get Google API key in Flutter Application如何在 Flutter 应用程序中获取 Google API 密钥
【发布时间】:2020-10-23 23:14:54
【问题描述】:

我已经使用https://pub.dev/packages/google_maps_flutter 为地图构建了一个 Flutter 应用程序,我想根据https://medium.com/@shubham.narkhede8/flutter-google-map-with-direction-6a26ad875083 添加方向,但我需要获取 Google API 密钥,该密钥在构建时以不同方式注入应用程序取决于是 Android 还是 iOS。

我用谷歌搜索了大约一个小时,但我找不到 Flutter 或本地获取应用程序中 API 密钥的方法。有什么办法吗?

【问题讨论】:

  • 您能说出您需要 API 密钥的用途吗?
  • 是的,它在上面的第二个链接中:maps.googleapis.com/maps/api/directions/json?origin=${l1.latitude},${l1.longitude}&destination=${l2.latitude},${l2.longitude}&key=$ apiKey
  • 您从 Google Cloud Console 获取 API 密钥。按照有关如何获取 API 密钥的说明进行操作,此 link 适用于 android,此 link 适用于 iOS。
  • 不,从 google 获取 API 密钥不是我的问题。见上文。
  • 如果您根据此medium.com/@shubham.narkhede8/… 文档添加了谷歌地图包,那么我认为您不需要在应用程序中获取 API 密钥。那么您能详细说明一下您的要求吗?

标签: google-maps flutter google-maps-flutter


【解决方案1】:

如果我正确理解您正在尝试从 Flutter 中的原生 iOS 和 Android 项目访问 Google Maps API 密钥,那么这应该可以:

使用这个:https://pub.dev/packages/flutter_native_config 来读取 Android 清单和 iOS Info.plist。

根据 Google 地图文档,在 Android 上,密钥已经存在。

然后,您需要将 iOS 中的 API 密钥移动到 info.plist,然后将其读入,而不是硬编码:https://www.hackingwithswift.com/example-code/system/how-to-read-your-apps-version-from-your-infoplist-file

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    相关资源
    最近更新 更多