管理谷歌地图API密钥 [英] Managing Google Maps API keys

查看:146
本文介绍了管理谷歌地图API密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用了大量的图形页面的屏幕,我试图找出如何管理的调试环境和生产之间的API密钥。显然,没有办法改变在Eclipse中调试应用程序键,所以我必须用在这种环境中调试的地图API密钥。相反,没有办法导出包进行beta测试,而不在生产应用的关键,所以我必须改变在每一个视图中的地图API密钥,以创建工作包。

My application uses a large number of MapView screens and I'm trying to figure out how to manage the API key between the debug environment and production. Apparently, there is no way to change the debug application key in Eclipse so I must use a debug map API key in that environment. Conversely, there is no way to export a package for beta testing without a production application key so I must change the map API key in every view in order to create a working package.

我的第一个想法就是要做到这一点:

My first idea was to do this:

所有MapView.xml文件有这样的:

All MapView.xml files have this:

android:apiKey="@string/googleMapsAPIKey"

然后在strings.xml中,我把这样的:

And then in strings.xml I put this:

<string name="googleMapsPIKey">@string/debugGoogleMapsAPIKey</string>
<string name="debugGoogleMapsAPIKey">TheMagicKeyString</string>

如果这个工作,那就让我改变一行在strings.xml中,所有的MapViews将在重建得到更新。但没有奏效。我猜的strings.xml不能使引用到自身。任何其他的想法?

If this worked, it would allow me to change a single line in strings.xml and all the MapViews would get updated in the rebuild. But it didn't work. I guess strings.xml can't make references into itself. Any other ideas?

感谢

推荐答案

我推荐一个更简单的方法,包括采取一种不太可能的优势,但更具体的资产的文件夹来保存调试的关键。要这样设置,创建一个文件RES /价值/图-apikey.xml包含以下内容:

I recommend a simpler approach that involves taking advantage of an unlikely, but more specific asset folder to house your debug key. To set this up, create a file res/values/maps-apikey.xml with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="maps_apikey">[productionApiKey]</string>
</resources>

然后每个开发者在本地将增加来自这一块RES /值-V1 /图-apikey.xml其中提供的调试API密钥导出的文件。在运行时,Android系统将有利于更具体的版本RES /值-V1 /图-apikey.xml所有Android版本(因为都是至少在API级别1或更高)。

Then each developer locally will add a file derived from this one in res/values-v1/maps-apikey.xml where their debug API key is provided. At runtime, the Android system will favor the more specific version res/values-v1/maps-apikey.xml for all versions of Android (since all are at least on API level 1 or higher).

像Git和SVN源代码控制系统允许你添加一个忽略文件,该文件指示忽略这个工具RES /值-V1 /图-apikey.xml文件,这样每个开发人员不小心将其提交到仓库。若要混帐做到这一点,只需添加一个文件RES /的.gitignore其中只包含该行的值-V1然后提交该文件。

Source control systems like git and svn allow you to add an "ignore" file which directs the tools to ignore this res/values-v1/maps-apikey.xml file so that each developer does not accidentally commit it to the repository. To do this for git, simply add a file res/.gitignore which contains only the line values-v1 then commit this file.

要发布你的软件,只需一个出口释放前删除RES /值-V1 /图-apikey.xml文件。由此产生的APK然后将引用版本RES /价值/图-apikey.xml这是您正确的生产重点。

To release your software, simply delete the res/values-v1/maps-apikey.xml file before exporting a release. The resulting APK will then reference the version in res/values/maps-apikey.xml which is your correct production key.

这篇关于管理谷歌地图API密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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