将Google Maps API v2集成到我的应用中时遇到了麻烦。
我正在使用Android Studio。我创建了一个新的地图活动,并按照google_maps_api.xml
中所述的说明进行了操作:
<resources>
<string name="google_maps_key_instructions">
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=XXXXhashXXX%3Bat.schickermueller.taxameter.activity
You can also add your credentials to an existing key, using this line:
XXXXhashXXX;at.schickermueller.taxameter.activity
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
</string>
<string name="google_maps_key" templateMergeStrategy="preserve">AIzaXXXXXXXXXXXXXXXXXXXXX</string>
</resources>
我还激活了Android maps v2 API:
但活动显示空白地图,并出现以下错误:
08-23 12:30:45.845 11659-11829 / at.schickermueller.taxameter E / Google Maps Android API:无法加载地图。联系Google服务器时出错这可能是一个身份验证问题(但可能是由于网络错误)。
我已经尝试了一些解决方案&#39;发布在堆栈溢出线程(如Android - Google maps Api v2 - Authentication error)
我的清单包含以下内容:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.schickermueller.taxameter" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".activity.StartActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".service.TrackService"
android:enabled="true"
android:exported="true" >
</service>
<activity
android:name=".activity.DriveListActivity"
android:label="@string/title_activity_drive_list" >
</activity>
<activity
android:name=".activity.DriveDetailActivity"
android:label="@string/title_activity_drive_detail"
android:theme="@style/Theme.AppCompat" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".activity.MapsActivity2"
android:label="@string/title_activity_maps_activity2" >
</activity>
</application>
<permission
android:name="at.schickermueller.taxameter.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="at.schickermueller.taxameter.activity.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>
我希望你能帮助我
答案 0 :(得分:0)
确保您已经注册了SH1密钥,API控制台中的包名“at.schickermueller.taxameter”对应于您的API密钥。或者使用可供所有设备使用的API密钥。