我遵循了本教程:如何在 Android Studio 中创建使用 Google Maps Api v2 的 Android 应用程序?
我编译并获得了在我的设备上运行的示例地图应用程序。唯一的问题是地图没有显示在我的应用程序中,我得到的只是空白屏幕。
我的 AndroidManifest.xml(我改变的只是 apikey)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="3"
android:versionName="2.2.1">
<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:icon="@drawable/ic_launcher"
android:label="@string/demo_title"
android:hardwareAccelerated="true">
<!-- ** You need to replace the key below with your own key. **
The example key below will not be accepted because it is not linked to the
certificate which you will use to sign this application.
See: https://developers.google.com/maps/documentation/android/start
for instructions on how to get your own key. -->
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="MyOwnGeneratedKey"/>
<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=".LegalInfoActivity"
android:label="@string/legal_info"/>
<activity
android:name=".LocationSourceDemoActivity"
android:label="@string/locationsource_demo"/>
<activity
android:name=".MarkerDemoActivity"
android:label="@string/marker_demo"/>
<activity
android:name=".MultiMapDemoActivity"
android:label="@string/multi_map_demo"/>
<activity
android:name=".MyLocationDemoActivity"
android:label="@string/my_location_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=".RawMapViewDemoActivity"
android:label="@string/raw_mapview_demo"/>
<activity
android:name=".RetainMapActivity"
android:label="@string/retain_map"/>
<activity
android:name=".SaveStateDemoActivity"
android:label="@string/save_state_demo"/>
<activity
android:name=".TileOverlayDemoActivity"
android:label="@string/tile_overlay_demo"/>
<activity
android:name=".UiSettingsDemoActivity"
android:label="@string/uisettings_demo"/>
</application>
</manifest>
我使用调试指纹在控制台中创建了密钥,它看起来像这样:
A1:FE:B5:E2:5E:0E:1A:8E:CC:8F:07:CC:4D:D0:95:13:0B:E7:1B:EC;com.example.mapdemo
用于地图的 Logcat:
08-03 02:41:14.330 13942-14784/com.example.mapdemo I/Google Maps Android API: Failed to contact Google servers. Another attempt will be made when connectivity is established.
08-03 02:41:29.840 13942-14812/com.example.mapdemo E/Google Maps Android API: Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).