谷歌地图Android的API V2 - 地图不显示
我跟着这个教程:How can I create an Android application in Android Studio that uses the Google Maps Api v2?谷歌地图Android的API V2 - 地图不显示
而且我编译,并得到样品的地图应用程序我的设备上运行。唯一的问题是地图不显示在我的应用程序中,我得到的只是空白屏幕。
我的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).
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="MyOwnGeneratedKey"/>
你需要使用Google API控制台来生成您自己的密钥
A1:FE:B5:E2:5E:0E:1A:8E:CC:8F:07:CC:4D:D0:95:13:0B:E7:1B:EC;com.example.mapdemo
然后在清单中将其替换。格式应该是类似于
AIzaSyB-sKpf4b9kSM6DX40WyjExC7VTRabAvcw
此外,您还需要轻弹在服务页面上的谷歌地图API第2开关API控制台中的东西。
我做到了;)我有我自己的密钥清单,我输入MyOwnGeneratedKay只是为了张贴在这里:) – pawel
@pawel显示您的地图activitty代码和xml布局 – Raghunandan
更新您的谷歌通过Android的SDK管理器播放服务,然后在Eclipse中导入它,因为它有新的更新使用它,然后将这些行添加到从您maifest-
缺少元素中的清单文件<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
从设备上卸载应用程序并安装新版本。
[检查此帖](http://stackoverflow.com/questions/17679317/android-google-maps-v2-authentication-error/17684309#17684309),如果是这样的话。 –
您必须使用释放键,而不是调试键。 – svlzx