【发布时间】: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' -
尝试在清单文件中添加
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> -
@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