简体   繁体   English

Google Maps API V2'无法加载地图。 即使我检查权限和密钥库也无法联系Google服务器

[英]Google Maps API V2 'Failed to Load Map. Could not contact Google Servers', Even I check permission and keystore

I follow the guide to create a google map sample, 我按照指南创建了Google地图示例,

but it always throw following error. 但它总是引发以下错误。

E/Google Maps Android API(27821): Failed to load map.  Could not contact Google servers.

permission READ_GSERVICES and debug and release keystore have been tested. 权限READ_GSERVICES以及调试和发布密钥库已经过测试。 They also can't resolve above problem. 他们也无法解决上述问题。 Could anyone tell me why it throw that error? 谁能告诉我为什么会引发该错误?

Manifest file: 清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.where.common"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
    <permission
        android:name="com.where.common.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.where.common.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.com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <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" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyDawEkMP7gdiB4nOOkXcdUcxSAvm0kfCmI" />
        <activity
            android:name="com.where.common.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>
    </application>
</manifest>

Java file: Java文件:

package com.where.common;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @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;
    }

}

View file: 查看文件:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

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. 您必须改用调试密钥库证书指纹。

在尝试新的API KEY之前,请不要忘记清除程序缓存:)因为即使您更改API密钥,Android也会使用第一个API密钥。

did you added all the other need permissions? 您是否添加了所有其他需要的权限?

<permission android:name="com.eadesign.skygiraffefinalv2.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.eadesign.skygiraffefinalv2.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<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-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

UPDATE: 更新:

1. The meta-data part should be at the most lower part of the application tag, like so: 1. meta-data部分应位于应用程序标签的最下部,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.where.common"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
<permission
    android:name="com.where.common.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.where.common.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.com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.where.common.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="AIzaSyDawEkMP7gdiB4nOOkXcdUcxSAvm0kfCmI" />
</application>

2. another problem I see is that you develop your application for API V8, so you have to use the SupportMapFragment and FragmentActivity for your Activity . 2.我看到的另一个问题是您为API V8开发了应用程序,因此必须对Activity使用SupportMapFragmentFragmentActivity

3. and last thing for your Map to work you have to add an License activity for Google Licensing info. 3.要使您的地图正常工作,您还必须为Google许可信息添加许可活动。

Finally, I find why this would happen. 最后,我找到了为什么会发生这种情况。 Because I write 因为我写

<uses-permission android:name="android.permission.com.google.android.providers.gsf.permission.READ_GSERVICES" />

It is wrong. 这是错误的。 It should be 它应该是

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

Here I thanks for Emil Adz's patience to help me! 在此,我感谢Emil Adz的耐心帮助!

I had same problem. 我有同样的问题。 After creating API key a lot of time,the problem still exists. 长时间创建API密钥后,问题仍然存在。 Then i simply uninstall the application and installed it again.basically the application is storing wrong api key credentials in the cache memory.And when we rerun the the app,It just loads it from cache.So installing the application again solves my problem. 然后我简单地卸载应用程序并重新安装。基本上,该应用程序将错误的api密钥凭据存储在缓存中。当我们重新运行该应用程序时,它只是从缓存中加载它。因此,再次安装该应用程序可以解决我的问题。

Did you solve the problem? 您解决问题了吗? May be this is the problem -> 可能是这个问题->

Wrong service was enabled. 启用了错误的服务。 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密钥。 ( https://stackoverflow.com/a/13805807/1300982 ) https://stackoverflow.com/a/13805807/1300982

If this is the problem, do not forget to Regenerate the API Key. 如果这是问题所在,请不要忘记重新生成API密钥。

我通过将支持添加到布局类的片段中解决了这个问题:

class="com.google.android.gms.maps.SupportMapFragment"

I had a similar issue as user2204477. 我有一个与user2204477类似的问题。 I had 我有

<uses-permission android:name="com.google.android.providers.gsf.permissions.READ_GSERVICES" />

It should be 它应该是

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

Note the wrong one says "permissions" and the correct one says "permission". 注意错误的人说“权限”,正确的人说“权限”。 I just wasted 5 hours trying to figure this out lol. 我只是浪费了5个小时试图找出答案。

I had same problem! 我有同样的问题! Reinstalled it 50 times. 重新安装了50次。 Just clear cache and remove all data for application on Android device before deleting. 只需清除缓存并删除所有数据,然后再在Android设备上删除该数据即可。 It helps, thanks to Gods... 感谢上帝,这有帮助...

Check permissions 检查权限

<uses-permission android:name="android.permission.INTERNET" />
<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-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

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

声明:本站的技术帖子网页,遵循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' 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