【问题标题】:Google Maps not loading when key restrictions are enabled: Android启用关键限制时谷歌地图未加载:Android
【发布时间】:2018-02-05 14:47:57
【问题描述】:

我知道这已经被问过好几次了,但我不确定我的修复是否正确。我在我的应用程序中使用谷歌地图。谷歌地图没有加载,我收到错误,

E/Google Maps Android API﹕ Authorization failure
Ensure that the "Google Maps Android API v2" is enabled.

我的清单有,

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />

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

我的gradle文件在下面,

dependencies {
  compile 'com.android.support:appcompat-v7:26.0.1'
  compile 'com.google.android.gms:play-services:8.4.0'
  compile 'com.google.android.gms:play-services-maps:8.4.0'
  compile 'com.google.android.gms:play-services-analytics:8.4.0'
}

编辑:

我的片段,

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/map"
 android:name="com.google.android.gms.maps.SupportMapFragment"
 android:layout_width="match_parent"
 android:layout_height="100dp" />

这是我使用片段的布局,

    <RelativeLayout
      android:id="@+id/map_area"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" >

      <fragment 
         android:id="@+id/map" 
         android:name="com.google.android.gms.maps.SupportMapFragment"
         android:layout_width="match_parent"
         android:layout_height="100dp"
         android:layout_marginTop="0dp" />

     <Button
          android:id="@+id/map_button"
          android:layout_width="match_parent"
          android:layout_height="50dp"
          android:layout_below="@+id/map"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="0dp"
          android:text="View Map and Directions"
          android:textColor="#ffffff"
          android:textStyle="bold" />
      </RelativeLayout>

我浏览了以下一些链接,但这些链接似乎都不起作用,

在浏览了几个链接之后,我设法让我的谷歌地图从谷歌控制台中移除了关键限制。这是正确的解决方案吗?谁能帮我解决 Google 地图的问题?

注意:我已经在控制台中启用了 Google Maps API。

【问题讨论】:

  • 发布您的gradle 文件,是否添加此依赖项'com.google.android.gms:play-services'
  • 尝试在清单文件中添加&lt;meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /&gt;
  • @Gowthaman gradle 文件已经存在了。
  • @ArpitPrajapati 我的 gradle 文件中已经有了这个。现在用它编辑了这个问题。
  • 发布您的 .xml 文件,其中包含片段标签并删除 compile 'com.google.android.gms:play-services-maps:8.4.0',因为当您拥有 compile 'com.google.android.gms:play-services:8.4.0' 时,您不需要添加 compile 'com.google.android.gms:play-services-maps:8.4.0'

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


【解决方案1】:

您需要从 google 控制台启用 google map api

以下是启用 google map api 的步骤。

  • Go to Google API console
  • 单击下拉菜单并选择“创建项目”。 输入项目名称。
  • 现在单击导航抽屉并选择 API 管理器。 启用 google 地方 api。

【讨论】:

  • 我已经在控制台中启用了 Google Maps API。当我从控制台将键限制设置为 NONE 时,我的 Google 地图也在加载。
猜你喜欢
  • 2015-08-14
  • 2015-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-10
  • 2012-09-10
相关资源
最近更新 更多