Android Studio-Google地图不显示地图

时间:2019-05-17 17:36:18

标签: android google-maps

我正在尝试使用Android Studio中的Google Maps API创建一个Google Maps活动。我生成了API密钥,并将其粘贴到google_maps_api.xml`中。我的清单文件是:

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

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality.
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <permission android:name="com.example.l5434.project" android:protectionLevel="signature"/>


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/.
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name="pubsub.subscriber.MapsActivity"
            android:label="@string/title_activity_maps"></activity>
        <activity android:name="pubsub.subscriber.SubscriberActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我还在compile 'com.google.android.gms:play-services-maps:+'中添加了依赖项build.gradle,但是并不能解决问题。 这是启动地图活动时模拟器的外观。

enter image description here

你知道怎么了吗?

1 个答案:

答案 0 :(得分:1)

此问题通常与用于签名清单的地图API密钥有关。看一下this帖子和this one,它们描述了您遇到的同一错误。在这两种情况下,都是因为它们使用的API密钥是用错误的密钥库创建的。在Google API控制台中创建API密钥

时,需要确保使用调试keystore