Failed to load map. Error contacting Google servers issue with android google maps api v2 [duplicate]
Asked Answered
L

17

24

I have been trying to app a Google Map in my Android app using the v2 API for the past two days, with no success. All I get every time is a

Google Maps Android API(16603): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

I have followed Google's setup tutorial (https://developers.google.com/maps/documentation/android/start), tried multiple times with different projects in different workspaces, tried different Google accounts, gone through various answers and suggestions here in StackOverflow, but to no avail.

I am using Eclipse 4.2.2 with Android SDK Tools 22.01 and I have installed Google Play services (rev. 7), also I have imported google-play-services_lib into my workspace and added a reference to that to my android project.

Here is my code:

AndroidManifest.xml:

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

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

<permission
    android:name="com.example.googlemapdemo.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.googlemapdemo.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" />
<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.example.googlemapdemo.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="my_api_key" />
</application>

</manifest>

activity_main.xml:

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

MainActivity.java

package com.example.googlemapdemo;

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

}

Also I created an API Project on https://code.google.com/apis/console/ where I have enabled the Google Maps Android API v2 service. Then I obtained my SHA1 debug certificate fingerprint using

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

and entered that and the package name in the API console, got the API key and put it in the manifest (where my_api_key is). This procedure I repeated a number of times, regenerating the key but with the same result.

Could anyone help with this or suggest anything else I could try? Any help will be greatly appreciated!

Longdrawn answered 5/7, 2013 at 14:37 Comment(7)
Did you completely removed the app from the phone and reinstalled it?Valer
Yes, multiple times, also tried different projects-apps. Result is the same.Longdrawn
Did you generate the API key ?Coprolite
Yes, and tried regenerating it multiple times. I also tried from different google accounts.Longdrawn
Reinstalling the app was the solution for me :DRosinweed
Yip, this worked for me also.Mailer
Also adding new key in Google Console takes some time to propagate.Kowtko
L
22

Found it after all, after turning off WiFi on the device I was using. It seems that when debugging over WiFi you also need the

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

in the manifest. Don't know if it was just my case or it's a general thing, but I guess it should be in the documentation somewhere (it's not).

So if you are reading this and having similar problems try either disabling WiFi or adding the above permission alongside the others.

Longdrawn answered 8/7, 2013 at 13:28 Comment(6)
Yes! Thank you. The API v2 tutorial suggests the android.permission.ACCESS_NETWORK_STATE permission, but not android.permission.ACCESS_WIFI_STATE.Psalm
this do not help me. but I find solution, look my answer here: https://mcmap.net/q/458692/-failed-to-load-map-error-contacting-google-servers-this-is-probably-an-authentication-issueSoutane
Didn't help me but when I cleared the data and uninstalled the app, maps are working now.Showdown
pharlez, I got even wifi enabled and required permission but map fails to load with exactly the same error you get.Inquiring
I can also confirm that adding the (not documented as required) permission android.permission.ACCESS_WIFI_STATE fixed my problem.Cheery
Just clear data (Setting->App-select app-Clear data->uninstall) and try. this worked for me. if you are created SHA1 code from custom keystore use the same in release mode. or generate apk by signing with that keystore.Greave
D
25

Simple.

If you are sure that the API key is right, and this error still comes up Logcat, then try this:

  1. Uninstall app from device.
  2. Clean the project
  3. And run on device again

The map should now display on the device....this worked for me .. cheers :)

Deferent answered 15/8, 2013 at 17:32 Comment(0)
L
22

Found it after all, after turning off WiFi on the device I was using. It seems that when debugging over WiFi you also need the

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

in the manifest. Don't know if it was just my case or it's a general thing, but I guess it should be in the documentation somewhere (it's not).

So if you are reading this and having similar problems try either disabling WiFi or adding the above permission alongside the others.

Longdrawn answered 8/7, 2013 at 13:28 Comment(6)
Yes! Thank you. The API v2 tutorial suggests the android.permission.ACCESS_NETWORK_STATE permission, but not android.permission.ACCESS_WIFI_STATE.Psalm
this do not help me. but I find solution, look my answer here: https://mcmap.net/q/458692/-failed-to-load-map-error-contacting-google-servers-this-is-probably-an-authentication-issueSoutane
Didn't help me but when I cleared the data and uninstalled the app, maps are working now.Showdown
pharlez, I got even wifi enabled and required permission but map fails to load with exactly the same error you get.Inquiring
I can also confirm that adding the (not documented as required) permission android.permission.ACCESS_WIFI_STATE fixed my problem.Cheery
Just clear data (Setting->App-select app-Clear data->uninstall) and try. this worked for me. if you are created SHA1 code from custom keystore use the same in release mode. or generate apk by signing with that keystore.Greave
T
10

Make sure you follow the instructions carefully in the documentation found at:

https://developers.google.com/maps/documentation/android/start#obtain_a_google_maps_api_key

As of the new ADT you should see an error message in the logcat viewer which gives you explicit instructions such as where to go, what to enable and the details you need to paste into the android fingerprint and app details. See below;

enter image description here

A few Gochas;

  1. Enable BOTH Google Maps Android API v2 AND Google Play Android Developer API in the developer console! This got me :)

  2. Make sure you are using the correct keystore to find the SHA1 hash (this can be found by going to window->preferences->android->build and look for SHA1) This will differ from your production keystore! Otherwise you can use keytool -list -v -keystore YOURKEYSTORE.keystore -alias YOURALIAS to view the SHA1

  3. Add your elements INSIDE your tags

  4. Add your elements INSIDE the <.manifest> tag (above the tag)

Tergiversate answered 18/6, 2014 at 9:55 Comment(0)
A
5

This permission solved the problem

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
Adipose answered 12/12, 2013 at 13:6 Comment(0)
P
3
<meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="my_api_key" />

android:value="my_api_key" should be an actual key that you get from https://code.google.com/apis/console

Prowler answered 5/7, 2013 at 14:44 Comment(7)
I know, I wrote it in the end of my question, I got an actual key from the API console and put it there, also tried with multiple keys.Longdrawn
My apologies.. try adding: GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.the_map)) .getMap(); in your onCreate method. Also my map fragment looks like this: <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.MapFragment" /> Maybe try changing it to that and see if that works?Prowler
Tried it just now, same result...Longdrawn
@Longdrawn have you referred to the google play services library project. have you enabled maps for android in the api console?Jaf
@Jaf I enabled maps android api v2 from the api console, also I imported google-play-services_lib in Eclipse and referenced it in my android project through Properties/AndroidLongdrawn
@Longdrawn do you have internet permission in manifest file?Jaf
@Longdrawn it should work. can't think of any other reason.Jaf
G
3

I ran into the same problem and found that this set of permissions works.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
Gull answered 22/10, 2013 at 20:53 Comment(0)
B
2

I think it is the problem of your API Key.

Try the Android Sample project for maps(Google play service) from new project.

and add your API key into maps AndroidManifest.xml file.

If it is not working then it will be the problem of API Key.

Boner answered 11/7, 2013 at 16:2 Comment(0)
M
2

Just spend a few frustrating hours with this exact same issue.

Was trying to run the mapdemo application from Google. Generated new keys etc still would not run.

Simple solution as detailed above was to delete the app from the tablet and run again for eclipse. Problem went away.

In Eclipse: Window, Preferences, Android, Build, SHA1 fingerprint from the debug keystore is the value you need (this matches the Google documented way using Keytool form the command line).

Mailer answered 30/7, 2013 at 16:27 Comment(0)
R
2

The answer for my similar issue is to add:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Remanent answered 18/9, 2013 at 15:1 Comment(0)
S
2

Make sure the "Google Maps Android API v2" is enabled, under Google APIs console, Services (see screenshot below. If it's not enabled, you will not get an error saying the service is disabled although you entered the SHA1 key.

Screenshot

Spotless answered 29/5, 2014 at 12:58 Comment(0)
B
2

My solution was use the correct file

in my case i used debug.keystore in C:\Users\.android for generate SH1 KEY

after try meny times, a found anoter file in C:\Users\\Downloads\adt-bundle-windows-x86_64\adt-bundle-windows\sdk.android an use it, for generate SH1 Key

and then copy 45:B5:E4:6F:36:AD:0A:98:94:B4:02:66:2B:12:17:F2:56:26:A0:E0 values the api key site

All Work again

Buonomo answered 5/6, 2014 at 19:52 Comment(0)
C
2

just to say, I was sure that I did everything well, but I finally noticed that the name of the package in the project was not the same as the one declared in the AndroidManifest.xml, so not the same as in Google APIs console.

Guess what, I changed it and... tadaa it worked !

So for who comes here, check that too !

Casket answered 6/6, 2014 at 7:27 Comment(0)
T
1

Make sure you have apk signed with right key

http://developer.android.com/tools/publishing/app-signing.html

Tranquillize answered 14/9, 2013 at 22:17 Comment(0)
S
1

I have found new Solution that was my silly mistake.

May you have changed you application package name after Google Map Integration.

One SHA1 certificate fingerprint and package name (separated by a semicolon) per line. Example:

45:B5:E4:6F:36:AD:0A:98:94:B4:02:66:2B:12:17:F2:56:26:A0:E0;com.example

Check Google API Console

Stenophyllous answered 26/3, 2014 at 6:51 Comment(1)
I did exact same mistake :) Updating that worksWhirlwind
T
0

I have solved this kind of problem, i hope people who find the same problem with me(hopefully nobody else ever do the same mistake) will find this helpful

my cause was i made a mistake when i created the project, the package name was wrong then i changed the package name of the project, this will produce 2 applications with same name but different package name. starting from here the maps didnt work anymore. then even if i changed the server side google api key, it still wont work.

solution: try to uninstall both of apps first then clean the solution. and the map shows up again.

Trapeze answered 25/9, 2013 at 16:53 Comment(0)
G
0

After spending several hours and following every tip on stackoverflow, I made it work trying one last thing.

I wanted my Map to display in another activity which I call mapActivity not the mainActivity. so when I created the sh1 key in google console api I typed package name for my mapActivity.

!!BUT it always needs to be the package name of the main activity even though you don't display the map there, so = packagename.appname from mainactivity

Gasiform answered 22/5, 2014 at 14:0 Comment(1)
Not really - the package name the API key wants is the one declared in your AndroidManifest.xml.Wildwood
P
0

Make sure that you are using the debug certificate fingerprint and not a release fingerprint in the Google Developers Console. Instructions on finding your debug key can be found here.

Palindrome answered 10/7, 2014 at 19:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.