简体   繁体   English

授权失败。 无法加载地图。 无法联系Google服务器。 (适用于Android的Google Map)

[英]Authorization failed. Failed to load map. Could not contact Google servers. (Google Map for Android)

I have been in this problem for a day now. 我已经在这个问题上待了一天。 I have followed and even changed to exactly alike from the tutorials. 我已经按照教程进行学习,甚至更改为完全相同。 I can't seem to understand what's the problem. 我似乎无法理解问题所在。 Everytime I run it to my device the map doesn't load and in LogCat it says: 每次我将其运行到设备上时,地图都不会加载,并且在LogCat中显示:

05-08 16:21:02.130: E/Google Maps Android API(28021): Failed to load map. Could not contact Google servers.

Here's my layout main.xml: 这是我的布局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>

Here's the AndroidManifest.xml: 这是AndroidManifest.xml:

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

<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"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="com.example.gmapactivity.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>

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="the-generated-api-key-from-console" />   
</application>

</manifest>

Finally my MainActivity.java: 最后是我的MainActivity.java:

package com.example.gmapactivity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

I have deleted my android key and regenerated from my debug keystore which is also the default debug keystore in Eclipse. 我已经删除了Android密钥,并从调试密钥库中重新生成了调试密钥库,这也是Eclipse中的默认调试密钥库。 Used the generated SHA1 key to the Google API with the service Google Maps Android API v2 and applied the API key to the manifest. 将生成的SHA1密钥与Google Maps Android API v2服务一起用于Google API,并将API密钥应用于清单。 Still no luck. 仍然没有运气。 I'd be very grateful if someone could suggest a solution. 如果有人可以提出解决方案,我将不胜感激。

You have applied wrong permissions: 您应用了错误的权限:

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

Should be this: 应该是这样的:

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

And in your layout file: Those parameters: 在布局文件中:这些参数:

map:cameraTilt="45"
map:cameraZoom="14"

Should be applied to the fragment and not to the RelativeLayout . 应该应用于片段,而不是应用于RelativeLayout

Have you added your package to the API Access in Google APIS? 您是否已将软件包添加到Google APIS的API Access中?

You should have something similar to this in the "Edit allowed Android apps": 您应该在“编辑允许的Android应用程序”中具有与此类似的内容:

FD:F4:....:D2;com.example.gmapactivity

The first parameter is as you said the SHA-1 of the signing key and the second is your application package 第一个参数是您所说的签名密钥的SHA-1,第二个参数是您的应用程序包

Also, from your code, you are loading the main.xml to the Options menu, not the view of the fragment (which is activity_main.xml). 另外,从您的代码中,您正在将main.xml加载到“选项”菜单,而不是片段的视图(即activity_main.xml)。 Change your 改变你的

setContentView(R.layout.activity_main);

to

setContentView(R.layout.main);

Okay, so I have been doing it correctly. 好吧,所以我一直做得正确。 It's just that I've been compiling it to a 3.2 android device instead of a 4.0 device, and now it works! 只是我一直在将其编译为3.2 android设备而不是4.0设备,现在它可以工作了! I just don't understand the reason why 3.2 version with API level 15 won't give result when my targetSdkVersion is 17? 我只是不明白为什么我的targetSdkVersion为17时API级别为15的3.2版本无法给出结果的原因?

Dont get panic . 不要惊慌。 simple way u can make it successful. 您可以使成功的简单方法。

if you are very sure about API key in manifest file and google play service library then. 如果您非常确定清单文件和Google Play服务库中的API密钥,那么。 follow the steps. 按照步骤。

1) Uninstall your app from Device 2) Clean the project 3) Run the app again 1)从设备上卸载应用程序2)清理项目3)再次运行应用程序

This should work . 这应该工作。 and this solution worked for me ..cheers :) 这个解决方案为我工作..欢呼:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “无法加载地图。 无法联系Google服务器。“ - “Failed to load map. Could not contact Google servers.” 修复无法加载地图。 无法联系Google服务器。 - Fix the Failed to load map. Could not contact Google servers. Google Maps android中的错误“android无法加载地图。 无法联系Google服务器。“ - Error in Google Maps android “android Failed to load map. Could not contact Google servers.” Android地图:无法加载地图。 无法联系Google服务器 - Android Maps: Failed to load map. Could not contact Google servers 无法加载地图。 无法联系Google服务器 - Failed to load map. Could not contact Google servers 无法加载地图。 无法联系Google服务器 - Failed to load map. Could not contact Google servers Android版Google地图。 无法加载地图。 无法联系Google服务器 - Google Maps for Android. Failed to load map. Could not contact Google servers Google Maps Android API v2:无法加载地图。 无法与Google服务器联系 - Google Maps Android API v2: Failed to Load Map. Could not contact Google Servers Google Maps Android API:无法加载地图。 与Google服务器联系时出错。 SSL固定实施后,这可能是身份验证问题 - Google Maps Android API: Failed to load map. Error contacting Google servers. This is probably an authentication issue after SSL Pinning implementaion Google Maps API V2&#39;无法加载地图。 无法联系Google服务器 - Google Maps API V2 'Failed to Load Map. Could not contact Google Servers'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM