我有一个旧的Android项目,其中使用了Location API和Google Map。我发现许多API已更新。如果我从Android Studio for Map活动生成一个新项目,它将生成文件并指示如何获取Google API密钥以及如何在google_maps_api.xml(debug)文件中添加该密钥。这是在app / debug / res / values / google_maps_api.xml中生成的。该文件值在AndroidManifest.xml中以
读取 <meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
我想对现有的旧Android项目执行相同的操作。我生成google API密钥,并将其添加到
到AndroidManifest.xml中 <meta-data
android:name="com.google.android.geo.API_KEY"
android:value="xxxxxxxxxx" />
xxxxxxxxxx =来自Google控制台的实际API密钥。
但是它不起作用。我可以看到一张空白地图。还在logcat中显示:-
E / Google Maps Android API:授权失败。请参阅 https://developers.google.com/maps/documentation/android-api/start的 如何正确设置
那么如何在现有的旧Android项目中正确添加它呢?
答案 0 :(得分:0)
问题出在您的Api密钥中。请检查您的api密钥。
我通过放置我的Api密钥及其工作来测试了您的地图。
请生成新的Api密钥并尝试。
请按照以下步骤获取API密钥:
Go to the Google Cloud Platform Console.
1.Create or select a project.
2.Click Continue to enable the API and any related services.
3.On the Credentials page, get an API key.
Note: If you have an existing unrestricted API key, or a key with browser restrictions, you may use that key.
这是我的地图屏幕截图
答案 1 :(得分:0)
尝试获取新的API key。当前密钥可能已失效
...由于软件包名称更改或签名密钥指纹更改。