Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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!

like image 592
pharlez Avatar asked Jul 05 '13 14:07

pharlez


People also ask

Why is my Google Maps API not working?

There are a several reasons why your google maps may not be working, the most common issue being no Google Map API key set or set incorrectly. To use the Google Maps JavaScript API, you must register your app project on the Google Cloud Platform Console and get a Google API key which you can add to your app.

How to Check Google map API is working or not?

Go to the Credentials section, which can be accessed from the left side bar under Google Maps Platform > Credentials. Check that the API key you currently use on your website is listed. If that's not the case, switch to a different project, and check the credentials there.

How to test Google API key?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key. Click Close.

What is API key in Android?

The API key is a unique identifier that authenticates requests associated with your project for usage and billing purposes. You must have at least one API key associated with your project.


2 Answers

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

like image 109
Pravin Mohol Avatar answered Oct 22 '22 09:10

Pravin Mohol


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.

like image 26
pharlez Avatar answered Oct 22 '22 09:10

pharlez