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

10 Answers 10

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.

2
  • Thanks alot @monika Sharma. After 3hrs of frustration,came out of it
    – Meher
    Apr 30, 2013 at 12:48
  • Oh my god I feel like such a doofus...I had 'Google Maps API v2' activated and not 'Google Maps Android API v2'... Jul 17, 2013 at 21:29
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.

2
  • ! 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, 2013 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, 2013 at 6: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.

15
  • Yes. I have added all permission.
    – xinglinCai
    Mar 24, 2013 at 12:48
  • did you checked those 2 posts: stackoverflow.com/questions/13727992/… and stackoverflow.com/questions/14497179/…
    – Emil Adz
    Mar 24, 2013 at 12:55
  • I have showed my files. I have check those two posts. I also try their methods, but failed.
    – xinglinCai
    Mar 24, 2013 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, 2013 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, 2013 at 13:13
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!

1
  • 1
    If his answer helped you out, you should give him an up vote as thanks.
    – jprofitt
    Mar 25, 2013 at 12:56
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.

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

0
0

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

class="com.google.android.gms.maps.SupportMapFragment"
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.

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.