授权失败。未能加载映射。无法联系谷歌服务器。(Android的谷歌地图)

授权失败。未能加载映射。无法联系谷歌服务器。(Android的谷歌地图),android,google-maps,google-maps-android-api-2,android-maps-v2,google-play-services,Android,Google Maps,Google Maps Android Api 2,Android Maps V2,Google Play Services,我已经陷入这个问题一天了。我已经跟随,甚至改变了完全一样的教程。我似乎不明白出了什么问题。每次我将其运行到我的设备时,地图不会加载,并且在LogCat中显示: 05-08 16:21:02.130:E/Google地图Android API(28021):无法加载地图。无法联系谷歌服务器。 以下是我的布局main.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns

我已经陷入这个问题一天了。我已经跟随,甚至改变了完全一样的教程。我似乎不明白出了什么问题。每次我将其运行到我的设备时,地图不会加载,并且在LogCat中显示:

05-08 16:21:02.130:E/Google地图Android API(28021):无法加载地图。无法联系谷歌服务器。

以下是我的布局main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    map:cameraTilt="45"
    map:cameraZoom="14" >

<fragment 
    android:id="@+id/the_map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.SupportMapFragment"
/>
</RelativeLayout>

我已经删除了我的android密钥,并从调试密钥库重新生成,调试密钥库也是Eclipse中的默认调试密钥库。将生成的SHA1密钥用于Google API和服务Google Maps Android API v2,并将API密钥应用于清单。还是不走运。如果有人能提出解决方案,我将不胜感激。

您应用了错误的权限:

<permission
  android:name="com.example.permission.MAPS_RECEIVE"
  android:protectionLevel="signature"/>
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.example.gmapactivity.permission.MAPS_RECEIVE"/>

应该应用于片段而不是
相对值yout

您是否已将包添加到Google API中的API访问中

您应该在“允许编辑的Android应用程序”中有类似的内容:

第一个参数是您所说的签名密钥的SHA-1,第二个参数是您的应用程序包

另外,从代码中,您正在将main.xml加载到选项菜单,而不是片段的视图(即activity_main.xml)。换衣服

setContentView(R.layout.activity_main);


好的,所以我一直在正确地做。只是我一直在把它编译成3.2安卓设备而不是4.0设备,现在它可以工作了!我只是不明白为什么API级别为15的3.2版本在我的targetSdkVersion为17时不会给出结果?

不要惊慌。你能成功的简单方法

若你们对清单文件和google play服务库中的API密钥非常确定的话。 按照步骤操作

1) 从设备卸载你的应用程序 2) 清理项目 3) 再次运行应用程序


这应该行得通。这个解决方案对我有效..干杯:)

也许是个垃圾问题,您的设备具有活动且工作的internet连接?您是否已在android:value中添加了密钥?您提供的清单中没有密钥,或者只是出于解释目的?我已将控制台生成的API密钥应用于android:value。我只是出于安全目的没有显示它。传输
map:cameraTilt=“45”map:cameraZoom=“14”
将给出错误“为标记片段找到意外的命名空间前缀”map”,因为您必须移动此行:xmlns:map=“”我以前也做过,但会为
xmlns:map=”添加另一个错误http://schemas.android.com/apk/res-auto“
这是为标记片段找到的
意外名称空间前缀“xmlns”
我确实应用了我的包,但直到com.example:
FD:F4:…:D2;com.示例
not
FD:F4:D2;com.example.gmapactivity
此外,我的布局中没有main.xml,因此可能会导致错误
main无法解析或不是字段
包必须与AndroidManifest.xml中定义的包相同。根据您的说法,完整的包是“com.example.gmapactivity”,所以它必须是这个包(而不是“com.example”),如果有人仍然在寻找答案,请检查这里-同样的问题:
<permission
  android:name="com.example.permission.MAPS_RECEIVE"
  android:protectionLevel="signature"/>
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.example.gmapactivity.permission.MAPS_RECEIVE"/>
<permission
 android:name="com.example.gmapactivity.permission.MAPS_RECEIVE"
 android:protectionLevel="signature"/>
<uses-permission android:name="com.example.gmapactivity.permission.MAPS_RECEIVE"/>
map:cameraTilt="45"
map:cameraZoom="14"
FD:F4:....:D2;com.example.gmapactivity
setContentView(R.layout.activity_main);
setContentView(R.layout.main);