无法在Android的谷歌地图活动

时间:2015-09-18 11:24:33

标签: android google-maps android-studio

我正在创建一个简单的Android应用程序,我想显示谷歌地图,所以我使用谷歌地图的活动,但当我在我的设备上运行应用程序时,我得到一个空白的屏幕与谷歌写在左下方 。 我使用了正确的API密钥。这是Logcat。我也找不到了 " Google Maps Android API v2"在Google Developer Console中。只有 我已启用的Google Maps Android API。

  Authentication failed on the server.
    09-18 16:38:47.158    2315-2451/? E/Google Maps Android API﹕ Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
    09-18 16:38:47.163    2315-2451/? E/Google Maps Android API﹕ In the Google Developer Console (https://console.developers.google.com)
        Ensure that the "Google Maps Android API v2" is enabled.
        Ensure that the following Android Key exists:
        API Key: AIzaSyA2PEin-GiKaerDpnoStcvKGmCmHJ2cZuI
        Android Application (<cert_fingerprint>;<package_name>): 85:84:5C:61:4D:15:26:5C:52:78:1F:86:9D:46:5A:C6:45:29:D1:B8;com.example.mapDemo
    09-18 16:38:49.438    5639-5639/? E/SQLiteLog﹕ (10) POSIX Error : 11 SQLite Error : 3850
    09-18 16:39:00.123  30704-30704/? E/[AccuTab]﹕ {[87A192EF54E76DF503A22F31216BFA0960788D40C82B44EE1702A58D5517331C]}
    09-18 16:39:00.123  30704-30704/? E/[AccuTab]﹕ {[5CD3AD49228511B775B4B89D43787C6921CE939C82941DF49B0235A31366AD0C155EAD47CE71200FB8BACB33B4B42DF281207C3087E99E0EA192762118CD2EC2]}
    09-18 16:39:13.708    3350-5382/? E/Watchdog﹕ !@Sync 391 [09-18 16:39:13.708]
    09-18 16:39:29.883    5639-5639/? E/SQLiteLog﹕ (10) POSIX Error : 11 SQLite Error : 3850
    09-18 16:39:43.708    3350-5382/? E/Watchdog﹕ !@Sync 392 [09-18 16:39:43.710]
    09-18 16:40:00.168  30704-30704/? E/[AccuTab]﹕ {[87A192EF54E76DF503A22F31216BFA09C9D803FB806A4AFA63BAF57FE025AD59]}
    09-18 16:40:00.173  30704-30704/? E/[AccuTab]﹕ {[5CD3AD49228511B775B4B89D43787C6921CE939C82941DF49B0235A31366AD0C155EAD47CE71200FB8BACB33B4B42DF281207C3087E99E0EA192762118CD2EC2]}
    09-18 16:40:13.708    3350-5382/? E/Watchdog﹕ !@Sync 393 [09-18 16:40:13.712]
    09-18 16:40:43.713    3350-5382/? E/Watchdog﹕ !@Sync 394 [09-18 16:40:43.714]
    09-18 16:40:51.918    5639-5639/? E/SQLiteLog﹕ (10) POSIX Error : 11 SQLite Error : 3850
    09-18 16:40:56.393    3350-5676/? W/ActivityManager﹕ ProcessRecord{a6c6e91 30584:com.google.android.youtube/u0a150} is already killed
    09-18 16:40:56.398    2649-2649/? E/lowmemorykiller﹕ Error writing /proc/30584/oom_score_adj; errno=22
    09-18 16:40:56.398    3350-5676/? E/JavaBinder﹕ !!! FAILED BINDER TRANSACTION !!!

这是清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mapDemo" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <!--
 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" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".SearchActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".SearchResultActivity"
            android:label="@string/title_activity_search_result" >
        </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=".MapsActivity"
            android:label="@string/title_activity_maps" >
        </activity>
    </application>

</manifest>

This is the what I am getting

我还在谷歌地图键中给出了api键。 enter image description here

enter image description here

2 个答案:

答案 0 :(得分:1)

搜索了好几个小时后,我知道我已将.android文件夹从C: drive移到D: drive,并将ANDROID_SDK_HOME设置为新路径,但我没有&删除上一个文件夹。我使用上一个路径来获取不正确的Certificate fingerprints: Md5 ,SHA1。这是我所做的唯一一次尝试,这就是Sha1不匹配的原因。

早些时候我正在使用这个

keytool -list -v -keystore "C:\.android\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

获取证书指纹,但现在我使用正确的路径

keytool -list -v -keystore "D:\.android\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

必须在console.developers.google.com上再次按照相同的步骤获取API密钥,现在我可以在屏幕上显示地图。

答案 1 :(得分:0)

您应该在google开发者控制台上启用“Google Maps Android API v2”API,并在Google控制台上生成任何Android密钥(API密钥:AIzaSyA2PEin-GiKaerDpnoStcvKGmCmHJ2cZuI),您应该将其放在清单文件中。