适用于Android的Google Maps的动态API KEY [英] Dynamic API KEY for Google Maps on Android

查看:173
本文介绍了适用于Android的Google Maps的动态API KEY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发使用Google地图的Android应用程序.

We are developing an Android application that uses google maps.

目前,出于开发目的,我们正在使用这样的密钥:

Right now, for development purposes, we're using the key like this:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

还有

<string name="google_maps_key">KEY_HERE</string>

出于部署目的,我们将实施自带密钥"方法,在该方法中,每个购买产品的客户都将其密钥也用于使用.

For deploying purposes, we will implement a "Bring Your Own Key" approach where each client that buys the product, also put his key to be used.

我知道这很奇怪,而且有些不必要,但这是一个大公司的过程,而这个决定来自高​​层".

I know it's weird and somewhat unnecessary, but it is a process from a big company and this decision comes from "the top".

有什么办法可以使用动态密钥?就像将密钥放入服务中并在应用程序中使用之类的东西一样?

Is there any way that we can have dynamic keys? Like putting a key into a service and consuming it in the app or something like that?

感谢任何帮助.

推荐答案

根据文档,这在Google API V2中是不可能的 必须使用清单文件来分配API密钥.

This is not possible in Google API V2 according to the documentation the API key has to be assigned using the Manifest file.

https://developers.google.com/maps/documentation/android /start#adding_the_api_key_to_your_application

但是对于MapView来说可能.

But its possible for MapView.

如果您直接从代码中实例化MapView,则应在MapView构造函数中传递Maps API密钥.

If you are instantiating a MapView directly from the code, you should pass the Maps API Key in the MapView constructor.

代码:

@Override
protected void onCreate(.....) {
     super.onCreate(....);
     mMapView = new MapView(this, YOUR_MAP_API_KEY); //pass key to MapView Constructor here
     setContentView(mMapView);
  //   ....
}

这篇关于适用于Android的Google Maps的动态API KEY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆