8

I follow the guide to create a google map sample,

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. 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:

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" />
swiftBoy
  • 35,607
  • 26
  • 136
  • 135
xinglinCai
  • 135
  • 1
  • 1
  • 9

10 Answers10

7

Make sure all below mentioned points are taken care:

1) 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.

2) Add the following elements to your manifest. Replace com.example.mapdemo with the package name of your application.

3) Use of correct certificate and key. 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.

Monika
  • 431
  • 4
  • 6
7

Don't forget to clear program cache before trying new API KEY :) Because Android is using first API key even if you change API key.

Emre Koç
  • 1,343
  • 1
  • 25
  • 44
  • ! 2 hours spended searching in code. Trying every silly solution. Installing and unistalling application. etc. etc. I thought i don't need to clear app data in debug. I don't smoke but have to smoke. Thanks. – Artur Aug 11 '13 at 12:02
  • Goodness, I googled for hours and found millions of suggestions on how to fix this problem... but nobody mentioned THIS! I finally got the MapDemo to work after uninstalling and reinstalling it. Thanks Emre! – EboMike Sep 13 '13 at 06:08
4

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:

<?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.

3. and last thing for your Map to work you have to add an License activity for Google Licensing info.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • Yes. I have added all permission. – xinglinCai Mar 24 '13 at 12:48
  • did you checked those 2 posts: http://stackoverflow.com/questions/13727992/google-maps-api-v2-failed-to-load-map-could-not-contact-google-servers and http://stackoverflow.com/questions/14497179/google-maps-android-api-v2-failed-to-load-map-could-not-contact-google-servers – Emil Adz Mar 24 '13 at 12:55
  • I have showed my files. I have check those two posts. I also try their methods, but failed. – xinglinCai Mar 24 '13 at 13:00
  • here I have a confusion. For the API layer, I create this project in Eclipse, it have mini API default. I choose Google APIs 16 as target API. – xinglinCai Mar 24 '13 at 13:11
  • Another question is what I see from many guide for google map example, they don't tell we should need License activity. – xinglinCai Mar 24 '13 at 13:13
  • when you set you target API version you should set it to the most newer one available and it come to describe what features do you desire to use in your application. while the MinAPI i set to describe what is the most lower API your application should work on. depending on weather you used newer API feature or not. – Emil Adz Mar 24 '13 at 13:15
  • I think the licencing is not necessary for testing but when you will publish you app you defiantly have to do it by the Google Map terms of service. – Emil Adz Mar 24 '13 at 13:27
  • Just now I created a new project by your advises to modify miniAPI and first suggestion. But it still can't work. I test it in my real device, but in my eclipse LogCat, I can see it endless loop for above error. – xinglinCai Mar 24 '13 at 13:46
  • here is a blog post I wrote on how to add a google map to your application: https://blog-emildesign.rhcloud.com/?p=435, try to follow it and tell me what is the result. – Emil Adz Mar 24 '13 at 13:48
  • I follow your post, but I find it still don't work. It throws same error. – xinglinCai Mar 24 '13 at 14:27
  • I don't why it fails even I follow your post. – xinglinCai Mar 24 '13 at 14:35
  • then it has to be something with the key you are generating or maybe the you are turning on the wrong API in the API Console. – Emil Adz Mar 24 '13 at 14:43
  • I find the reason. Thank you. – xinglinCai Mar 25 '13 at 12:55
  • Same here.Failed to load map. Could not contact Google servers.But i can see zoom controls. :( – Meher Apr 30 '13 at 12:43
  • so open a new question with your code and I will try to help you. – Emil Adz Apr 30 '13 at 12:47
4

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!

xinglinCai
  • 135
  • 1
  • 1
  • 9
4

I had same problem. After creating API key a lot of time,the problem still exists. 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.

2

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. (https://stackoverflow.com/a/13805807/1300982)

If this is the problem, do not forget to Regenerate the API Key.

Community
  • 1
  • 1
Hari Krishna Ganji
  • 1,647
  • 2
  • 20
  • 33
0

I solved this problem by adding Support to my fragment on the layout class:

class="com.google.android.gms.maps.SupportMapFragment"
Rob
  • 4,927
  • 12
  • 49
  • 54
0

I had a similar issue as 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.

Geore Shg
  • 1,299
  • 5
  • 23
  • 38
0

I had same problem! Reinstalled it 50 times. Just clear cache and remove all data for application on Android device before deleting. It helps, thanks to Gods...

Evgeny Borzenkov
  • 1,107
  • 3
  • 12
  • 19
0

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