简体   繁体   English

Google Maps API V2'无法加载地图。 无法联系Google服务器

[英]Google Maps API V2 'Failed to Load Map. Could not contact Google Servers'

I have checked and double checked my APIkey that I registered on the Google Console however I am still getting the following error: 我已经检查并仔细检查了我在Google控制台上注册的API密钥但是我仍然收到以下错误:

12-05 16:31:12.940: E/Google Maps Android API(12334): Failed to load map.  Could not contact Google servers.

What I am seeing is the zoom in/out buttons and the background for the MapView but no Map???!!! 我所看到的是放大/缩小按钮和MapView的背景但没有Map ??? !!!

Any ideas??? 有任何想法吗???

Answer 回答

I will post it here because what solved my issue was stated in the comments of the accepted answer below. 我将在此发布,因为解决了我的问题的原因已在下面接受的答案的评论中说明。

It was the READ_GSERVICES permission. 这是READ_GSERVICES权限。 For some reason the permission wasn't mentioned on the developer site when it came to using them. 出于某种原因,在开发人员网站上使用它们时未提及该权限。

For setting up Google Maps API v2 on Android, make sure that you have completed all of the following steps. 要在Android上设置Google Maps API v2,请确保您已完成以下所有步骤。

App Key For API Access API访问的应用密钥

When Google asks for the SHA1 fingerprint of your app certificate, you will want most likely want to run this twice, once for your debuging certificate, and once for your publishing certificate. 当Google要求提供应用程序证书的SHA1指纹时,您可能希望两次运行,一次用于您的debuging证书,一次用于您的发布证书。

keytool -list -v -keystore publishcert.keystore keytool -list -v -keystore publishcert.keystore
keytool -list -v -keystore ~/.android/debug.keystore keytool -list -v -keystore~ / .android / debug.keystore

The fingerprint of the app on the market is different then the fingerprint of an app that you are just testing! 市场上应用程序的指纹与您刚刚测试的应用程序的指纹不同!

Enable the service on the Google API Console 在Google API控制台上启用该服务

Login to the Google API Console . 登录Google API控制台
On the services page, find Google Maps Android API v2 . 在服务页面上,找到Google Maps Android API v2

Note - Google Maps API v2 is DIFFERENT then Google Maps Android API v2 - Google Maps API v2不同的 ,那么Google Maps Android API v2

In the API Access tab, click Create new Android Key 在“API访问”选项卡中,单击“ Create new Android Key

Add your certificate signatures for access to the APIs. 添加证书签名以访问API。

yourrelease-fingerprint;com.example.project.package yourrelease指纹; com.example.project.package
yourdebug-fingerprint;com.example.project.package yourdebug指纹; com.example.project.package

You will be provided with a generated API Access Key. 您将获得生成的API访问密钥。

You may need to first create an API Project in the API Console 您可能需要先在API控制台中创建API项目

Amend the App Manifest 修改App Manifest

Add your API Key, inside of the <application> element. <application>元素内添加API密钥。

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

Add the following permissions: 添加以下权限:

<permission
        android:name="com.example.project.package.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>

<uses-permission android:name="com.example.project.package.permission.MAPS_RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET" />
<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"/>

Add the following feature request: 添加以下功能请求:

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

Make sure all below mentioned points are taken care: 确保所有下面提到的要点都得到照顾:

1) Wrong service was enabled. 1)启用了错误的服务。 Make sure the " Google Maps Android API v2 ", not " Google Maps API v2 " is enabled and re-generate the API key. 确保已启用“ Google Maps Android API v2 ”,而非“ Google Maps API v2 ”并重新生成API密钥。

2) Add the following elements to your manifest. 2)将以下元素添加到清单中。 Replace com.example.mapdemo with the package name of your application. 将com.example.mapdemo替换为应用程序的包名称。

3) Use of correct certificate and key. 3)使用正确的证书和密钥。 Release certificate, which WILL NOT WORK during debugging when you run the app on my phone. 发布证书,当您在我的手机上运行应用程序时,调试期间无法正常工作。 You have to use the debugging keystore certificate fingerprint instead. 您必须使用调试密钥库证书指纹。

It could be an issue with the Manifest. 它可能是Manifest的一个问题。 The following works for me, specifically permission.MAPS_RECEIVE solved a similar issue I had: zoom buttons and myLocation displayed, but map had no tiles... 以下为我工作,特别是permission.MAPS_RECEIVE .MAPS_RECEIVE解决了我遇到的类似问题:缩放按钮和myLocation显示,但地图没有瓷砖......

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.discos2.example"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <permission
        android:name="com.discos2.example.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

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

    <uses-feature
        android:name="android.hardware.location"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location.network"
        android:required="false" />
    <uses-feature android:name="android.hardware.location.gps" />
    <uses-feature
        android:name="android.hardware.wifi"
        android:required="false" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:hardwareAccelerated="true">
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="__NEW_GOOGLE_MAPS_V2_KEY_GOES_HERE__" />

        <activity
            android:name=".ui.activities.MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

    </application>

</manifest>

BTW, I'm running Windows 7. I fussed over this for days, until I discovered the following: I have more than one debug.keystore. 顺便说一下,我正在运行Windows 7.我对此进行了几天的讨论,直到我发现以下内容:我有多个debug.keystore。 One is at: 一个是:

C:\android-sdk\.android\debug.keystore

And there's another, at: 还有另一个,在:

C:\Users\David\.android\debug.keystore

Once I found the "C:\\Users\\David.android\\debug.keystore" I did: 一旦我找到“C:\\ Users \\ David.android \\ debug.keystore”,我做了:

keytool -list -alias androiddebugkey -keystore C:\Users\David\.android\debug.keystore -storepass   android -keypass android -v

I submitted the resulting SHA1 to google console and got an API-key that works. 我将生成的SHA1提交给谷歌控制台并获得了一个有效的API密钥。 Getting the SHA1 from the keystore at "C:\\android-sdk.android\\debug.keystore" does not work. 从密钥库“C:\\ android-sdk.android \\ debug.keystore”获取SHA1不起作用。

I was facing the same issue ; 我面临同样的问题; but for me it was keystore issue I was signing it with debug keystore hence Google map api v2 was not able to connect to Google map. 但对我来说这是密钥库问题我用调试密钥库签名它因此谷歌地图api v2无法连接到谷歌地图。

I created a new api key using my-release-keystore.keystore (u can find it at C:\\Users\\{YOUR_USER_NAME}\\.android\\my-release-key.keystor e) generate SHA1 using keytool available in JDK; 我使用my-release-keystore.keystore创建了一个新的api my-release-keystore.keystore (你可以在C:\\Users\\{YOUR_USER_NAME}\\.android\\my-release-key.keystor找到它C:\\Users\\{YOUR_USER_NAME}\\.android\\my-release-key.keystor e)使用JDK中提供的keytool生成SHA1; copy it and register with google console. 复制它并注册谷歌控制台。

Use api key generated in your applications manifest file. 使用应用程序清单文件中生成的api密钥。 Sign it with my-release-key.keystore will pushing it on device. 使用my-release-key.keystore对其进行my-release-key.keystore将其推my-release-key.keystore设备上。

您可能启用了错误的服务“Google Maps Android API v2”,而不是“Google Maps API v2”

I had the same problem. 我有同样的问题。 I just simply missed this point: When you list your Google APIs services, there are three Google Maps API available. 我只是错过了这一点:当您列出Google API服务时,有三种Google Maps API可用。

Google Maps Android API v2 Google Maps Android API v2
Google Maps API v2 Google Maps API v2
Google Maps API v3 ... Google Maps API v3 ...

Check that you have Android version (Google Maps Android API v2) enabled, when you code for Android. 当您为Android编码时,请检查您是否启用了Android版本(Google Maps Android API v2)。 Google Maps API v2 was not good enough. Google Maps API v2还不够好。

Just create new API key with SHA and most importantly correct package name (like com.example.mapdemo). 只需使用SHA创建新的 API密钥,最重要的是正确的包名称(如com.example.mapdemo)。 Use the new generated key in your AndroidManifest.xml . AndroidManifest.xml使用新生成的密钥。

I guess we need new API key for all new eclipse projects which uses Google maps (as creating new key also requires the package name, which is essentially different for all projects). 我想我们需要新的API密钥用于所有使用Google地图的新eclipse项目(因为创建新密钥也需要包名称,这对于所有项目而言本质上是不同的)。

After spending many hours, the problem had been eventually solved: 花了好几个小时后,问题终于解决了:

if none of the above helped you solving your problem, try to put your api key into values/strings.xml 如果以上都没有帮助您解决问题,请尝试将api密钥放入values / strings.xml

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

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="map_key">YOUR_KEY</string>
</resources>

I did everything what was required to achieve this task. 我做了完成这项任务所需的一切。 My key, manifest, code etc. were all right. 我的密钥,清单,代码等都没问题。 But, in the end after wasting a lot of time, the debug keystore which I was using was the wrong one. 但是,最后浪费了很多时间后,我使用的调试密钥库是错误的。 It's was all about the SHA1 fingerprint after all. 毕竟这完全是关于SHA1指纹的。

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

相关问题 Google Maps Android API v2:无法加载地图。 无法与Google服务器联系 - Google Maps Android API v2: Failed to Load Map. Could not contact Google Servers Google Maps API V2&#39;无法加载地图。 即使我检查权限和密钥库也无法联系Google服务器 - Google Maps API V2 'Failed to Load Map. Could not contact Google Servers', Even I check permission and keystore Android地图:无法加载地图。 无法联系Google服务器 - Android Maps: Failed to load map. Could not contact Google servers Google Maps API v2。 加载地图失败。 无法连接到Google服务器 - Google maps api v2. Failed to Load Map. Could not connect to google servers Google Maps android中的错误“android无法加载地图。 无法联系Google服务器。“ - Error in Google Maps android “android 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服务器 - Failed to load map. Could not contact Google servers “无法加载地图。 无法联系Google服务器。“ - “Failed to load map. Could not contact Google servers.” 修复无法加载地图。 无法联系Google服务器。 - Fix the Failed to load map. Could not contact Google servers. 无法加载地图。 无法联系Google服务器 - Failed to load map. Could not contact Google servers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM