谷歌地图Android Api V2 - 地图不显示

时间:2013-08-03 00:53:59

标签: android google-maps-android-api-2

我遵循了本教程:How can I create an Android application in Android Studio that uses the Google Maps 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 for maps:

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).

2 个答案:

答案 0 :(得分:1)

    <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控制台的服务页面中轻触Google Map API v2上的开关。

答案 1 :(得分:0)

通过Android SDK Manager更新您的Google Play服务,然后通过在eclipse中导入它来使用它,因为它有新的更新,然后将这些行添加到元素中的清单文件中,这些文件在您的元素中缺失 -

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

从设备上卸载应用程序并安装新版本。