【问题标题】:Google Maps is not showing after adding to the working project添加到工作项目后,谷歌地图未显示
【发布时间】:2018-07-12 11:22:38
【问题描述】:

我尝试测试 Google 地图并创建了一个新项目,从 API 控制台获取了 API 密钥。一切正常,没有问题。但是,当我尝试将 Google Maps 活动添加到工作项目中时,通过将此活动作为午餐者,通过上述步骤,现在我收到以下错误:

Google Maps Android API:授权失败。请参见 https://developers.google.com/maps/documentation/android-api/start 为 如何正确设置地图。 E/Google 地图 Android API:在 谷歌开发者控制台 (https://console.developers.google.com) 确保启用了“Google Maps Android API v2”。确保这件事 存在以下 Android 密钥: API 密钥: AIzaSyA5iBkfmlihtkh2Xc6T61v109eFJ3OGZrE Android 应用程序 (;):

AndroidManifest.xml

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

    <!--
         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" />

    <application
        android:name=".AfexApp"
        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">
        <activity
            android:name=".activities.MainActivity"
            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=".activities.LoginActivity"
            android:label="Tizimga kirish" />
        <activity
            android:name=".activities.RegistrationActivity"
            android:label="Ro&apos;yxatdan o&apos;tish" />
        <activity android:name=".activities.Tovar_description_Activity" />
        <activity android:name=".activities.OmborActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        <activity android:name=".models.Switch_Mode" />
        <activity android:name=".activities.SettingActivity" />
        <activity
            android:name=".AddressActivity"
            android:label="@string/title_activity_address"
            android:theme="@style/AppTheme" />
        <activity android:name=".AddressAddingActivity" />
        <!--
             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=".activities.GoogleMapActivity"
            android:label="@string/title_activity_google_map">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

【问题讨论】:

  • @tahsinRupam 谢谢,但我已经阅读并完成了所有步骤。它没有帮助我
  • 仔细检查 Android 应用对 API 密钥的限制。包名和SHA1是否正确?
  • @xomena 一切都正确

标签: java android google-maps


【解决方案1】:

在 Google Developers Console (https://console.developers.google.com/) 中启用 Maps API。

【讨论】:

  • 我已经做到了。但是,仍然没有显示地图。仅在左下角出现 Google 徽标
  • 您是否在移动设备中授予了位置权限??
  • 是的。此外,正如我告诉谷歌地图在我创建它作为一个新项目时工作的那样。但是当我试图将它添加到我的另一个项目中时,谷歌地图无法正常工作
  • 如果您使用以前的项目包名称限制了您的 api 密钥,那么它将不适用于您的新项目。您必须生成一个新的 api 密钥。试试看,然后告诉我。
  • 我试过了。我删除了我的所有项目并从 google_maps_api.xml 中的给定链接创建新项目。但是还是不行
【解决方案2】:

那是因为您创建了一个带有地图活动的项目,但您正试图将该活动添加到另一个项目中。

您可能在Maps API in Google Developers Console中使用了地图活动项目的包名。

解决方案是,使用您实际项目的包名称创建一个新的地图 API 密钥,然后将 API 密钥用于您的项目。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多