我正在尝试使用 Google Play 服务(修订版 5)和 Google Maps Android API 的第 2 版构建一个 Android 应用程序。
我仔细阅读了以下文件:
http://developer.android.com/google/play-services/maps.html https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api
为了确定,我只是从以下位置复制了示例应用程序:~/android-sdk-linux/extras/google/google_play_services/samples
在这段代码中,我只是更改了 manifest 中的 developerper 密钥和 targetSdkVersion (16 -> 17):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="2"
android:versionName="2.1.0" >
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<!-- End of copy. -->
<application
android:hardwareAccelerated="true"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/demo_title" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="XXXXXXXXXXXmyXkeyXXXXXXXXXXXXX" />
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".BasicMapActivity"
android:label="@string/basic_map" />
<activity
android:name=".CameraDemoActivity"
android:label="@string/camera_demo" />
<activity
android:name=".CircleDemoActivity"
android:label="@string/circle_demo" />
<activity
android:name=".EventsDemoActivity"
android:label="@string/events_demo" />
<activity
android:name=".GroundOverlayDemoActivity"
android:label="@string/groundoverlay_demo" />
<activity
android:name=".LayersDemoActivity"
android:label="@string/layers_demo" />
<activity
android:name=".LocationSourceDemoActivity"
android:label="@string/locationsource_demo" />
<activity
android:name=".MarkerDemoActivity"
android:label="@string/marker_demo" />
<activity
android:name=".OptionsDemoActivity"
android:label="@string/options_demo" />
<activity
android:name=".PolygonDemoActivity"
android:label="@string/polygon_demo" />
<activity
android:name=".PolylineDemoActivity"
android:label="@string/polyline_demo" />
<activity
android:name=".ProgrammaticDemoActivity"
android:label="@string/programmatic_demo" />
<activity
android:name=".TileOverlayDemoActivity"
android:label="@string/tile_overlay_demo" />
<activity
android:name=".UiSettingsDemoActivity"
android:label="@string/uisettings_demo" />
<activity
android:name=".RawMapViewDemoActivity"
android:label="@string/raw_mapview_demo" />
<activity
android:name=".RetainMapActivity"
android:label="@string/retain_map" />
<activity
android:name=".MultiMapDemoActivity"
android:label="@string/multi_map_demo" />
</application>
Google Play 库项目已在项目属性中正确设置。
我没有修改 proguard.cfg 标准文件。
在我的带有 android 4.1.2 的 Motorola Xoom 上启动“Google Maps API Demos”,然后单击“基本地图”,返回一个没有任何地图的空白屏幕。
我的 logcat 包含:
03-17 14:07:13.450: E/Google Maps Android API(17988): Authorization failure.
在我的 API 控制台中,“Google Maps Android API v2”已打开。
我为 Android 应用程序创建了一个密钥,我的控制台显示:
Key for Android apps (with certificates)
API key: XXXXXXXXXXXmyXkeyXXXXXXXXXXXXX
Android apps: XXXXXXXXXXXmyXSHA1XXXXXXXXXXXXX;com.example.mapdemo
Activated on: Mar 17, 2013 4:28 AM
Activated by: you
你明白什么是错的吗?