13

I had tried to use the Google Map Sample Code before which was provided in Google_Play_SERVICE/SAMPLE by using all the available options and it showed the below Log.

01-14 17:58:39.773: E/Google Maps Android API(13114): Authorization failure.

It showed me the blank screen for all of the sample Map options.

Now I created a new Project and here is its complete code:-

Activity.java

public class MapActivity extends FragmentActivity
{
    private Context context = this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);

        GoogleMap gMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

        int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
        Log.e("Maps", "Result int value::" + result);
        switch (result) {
        case ConnectionResult.SUCCESS:
            Log.e("Maps", "RESULT:: SUCCESS");          
            break;

        case ConnectionResult.DEVELOPER_ERROR:
            Log.e("Maps", "RESULT:: DE");           
            break;

        case ConnectionResult.INTERNAL_ERROR:
            Log.e("Maps", "RESULT:: IE");           
            break;

        case ConnectionResult.INVALID_ACCOUNT:
            Log.e("Maps", "RESULT:: IA");           
            break;

        case ConnectionResult.NETWORK_ERROR:
            Log.e("Maps", "RESULT:: NE");           
            break;

        case ConnectionResult.RESOLUTION_REQUIRED:
            Log.e("Maps", "RESULT:: RR");           
            break;

        case ConnectionResult.SERVICE_DISABLED:
            Log.e("Maps", "RESULT:: SD");           
            break;

        case ConnectionResult.SERVICE_INVALID:
            Log.e("Maps", "RESULT:: SI");           
            break;

        case ConnectionResult.SERVICE_MISSING:
            Log.e("Maps", "RESULT:: SM");           
            break;
        case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
            Log.e("Maps", "RESULT:: SVUR");         
            break;
        case ConnectionResult.SIGN_IN_REQUIRED:
            Log.e("Maps", "RESULT:: SIR");          
            break;      

        default:
            break;
        }
        gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        gMap.setMyLocationEnabled(true);
        Log.e("Maps", "------EOC-------");
    }
}

activity_map.xml

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

Manifest.xml

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

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

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <permission
        android:name="net.dottech.map.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="net.dottech.map.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" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="net.dottech.map.MapActivity"
            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="removed" />
    </application>

</manifest>

LOG

01-21 13:09:09.243: E/Maps(449): Result int value::0
01-21 13:09:09.243: E/Maps(449): RESULT:: SUCCESS
01-21 13:09:09.243: E/Maps(449): ------EOC-------
01-21 13:09:09.248: D/LocationManagerService(1852): gps location requested by an application
01-21 13:09:09.253: D/SensorManager(449): registerListener :: handle = 0  name= K3DH 
Acceleration Sensor delay= 20000 Listener= maps.i.a@41a054f8
01-21 13:09:09.353: D/(449): Device driver API match
01-21 13:09:09.353: D/(449): Device driver API version: 10
01-21 13:09:09.353: D/(449): User space API version: 10 
01-21 13:09:09.353: D/(449): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Fri May  4 10:32:42 KST 2012
01-21 13:09:12.398: D/Sensors(449): Remain listener = Sending .. normal delay 200ms
01-21 13:09:12.398: I/Sensors(449): sendDelay --- 200000000
01-21 13:09:12.398: I/Sensors(1852): setDelay :: handle = 0   delay = 200000000
01-21 13:09:12.398: D/SensorManager(449): JNI - sendDelay
01-21 16:14:17.835: E/Google Maps Android API(12168): Failed to load map.  Could not contact Google servers.

Screenshot

Google Map Android Api V2 Example tried, no success

This is the result, Blank screen with zoom options, No map in MapView.

I have followed each and every step mentioned at:-

1.) Tutorial

2.) Google Map Android Api V2

DarthCaniac
  • 383
  • 5
  • 16
Cool Jatt
  • 403
  • 2
  • 6
  • 16
  • What device are you testing the app on? – CommonsWare Jan 08 '13 at 13:44
  • 1
    @CommonsWare: I have tried it on Samsung Galaxy Young, Samsung Galaxy Note 2 & Micromax A 52. – Cool Jatt Jan 08 '13 at 13:49
  • 1
    Are you sure you enabled "Google Maps Android API v2" service in Google console? – Yaroslav Mytkalyk Jan 08 '13 at 14:06
  • @DoctororDrive: Yes, I have enabled the Google Maps API v2 service in console and grabed the Android MapAPi KEY from there and have added it in the Manifest. – Cool Jatt Jan 08 '13 at 14:11
  • 5
    Are you sure it's "Google Maps Android API v2", not "Google Maps API v2"? I had a similar problem and that was the reason. – Yaroslav Mytkalyk Jan 08 '13 at 14:15
  • Check my question and answer here, http://stackoverflow.com/questions/13803833/map-api-v2-authorisation-failure/ maybe you will find something useful. – Yaroslav Mytkalyk Jan 08 '13 at 14:31
  • @DoctororDrive: I have checked your question & had edited my question too. Please check it once again. – Cool Jatt Jan 08 '13 at 15:07
  • Did you check to make sure your devices have google play services, as well as the latest version of "Maps" from the play store installed on the devices you're using? – DiscDev Jan 08 '13 at 17:01
  • @spotdog13,DoctororDrive: Yah, I have checked those things. Google Map & Play-services are up-to-date. Do we need to built it for any fixed Android OS version? I mean is there any minimum android version for the new API to which it is compatible? – Cool Jatt Jan 09 '13 at 12:23
  • Not sure about API min, but I wouldn't try with older than API 7. Also, did you do the check in the manifest to make sure your device supports OpenGL ES 2? There are directions on the google maps api v2 tutorial for adding that check to the manifest. – DiscDev Jan 09 '13 at 15:28
  • possible duplicate of [Google Maps API v2 shows shows blank map](http://stackoverflow.com/questions/14048381/google-maps-api-v2-shows-shows-blank-map) – Siddharth Lele Jan 23 '13 at 13:15
  • I had similar situation, but there was empty map in app and no error message at all. It turned out Maps v2 were not used after one of updates and got stuck somehow. It required reboot and Maps app start to make it running again - in Maps app and my app's Fragment as well. – tomash Mar 01 '13 at 16:36
  • What helped for me was deleting and recreating the key in the API Console. I could create a key and add an Android app, which worked. Then, when adding multiple apps to it, it stopped working. After deleting and recreating it suddenly started working again. This has happened multiple times to me. – Niels Jan 18 '13 at 13:07
  • Hi I have checked that too, no success buddy, please check the whole question again, I have added the complete code now. Thanks. – Cool Jatt Jan 21 '13 at 07:53
  • You may also look at this extensive checklist: http://stackoverflow.com/questions/13696620/google-maps-android-api-v2-authorization-failure/16144402#16144402 – Gunnar Bernstein Apr 26 '13 at 10:02
  • You may also look at this extensive checklist: http://stackoverflow.com/questions/13696620/google-maps-android-api-v2-authorization-failure/16144402#16144402 – Gunnar Bernstein Apr 26 '13 at 10:05

8 Answers8

27

Please check..

  1. check if the "libs" folder containing the "android-support-v4.jar" exists in your project.

    "android-support-v4.jar" is located in "/extras/android/compatibility/v4/android-support-v4.jar" under your "android-sdk" drectory.

  2. Before running your project, you must set your project Build target to "Google APIs", not Android x.x. version : Select your project and click Project > Properties > Project Build Target in Eclipse and select any "Google APIs ", and then run your project on your phone. If you use the emulator, also MUST set the AVD of the emulator to the any "Google APIs ".

  3. Once more, you don't need to create the new Google Maps API key in order to test your project, Just use the default provided API key, which is shown as "Key for browser apps (with referers) "in your Google APIs Console.

  4. Finally, the most important is to add Google Play services as an Android library project as follows:

    Select File > Import > Android > Existing Android Code Into Workspace and click Next. Select Browse..., enter /extras/google/google_play_services/libproject/google-play-services_lib, and click Finish.

Community
  • 1
  • 1
BBonDoo
  • 766
  • 5
  • 14
  • Thanks, third point helped me. I was trying earlier with Key for Android apps (with certificates) but it didnt work. – Harshal Kshatriya Apr 15 '13 at 07:27
  • Have read many questions on SO related to this.. But this is the best answer I came across. And it worked for me as well.. – ambit Jun 18 '13 at 17:26
15

I have compiled your code and I get maps working. I think I discovered the problem: wrong credentials got cached.

The first time I ran your code, it was using wrong credentials. Although I have fixed them, I was still getting the "authorization failure" error. Then I simply uninstalled the app, ran it again and then maps got working.

Apparently Google Maps credentials are cached somewhere. Simpling running the app again does not overwrite them.

That also explains why I only got maps working after running my other app using Debug As (not Run As)...

I had the same problem as you and I got maps working only when running the application on a real device through "Debug As > Android Application".

I'm a newbie in Android development. I don't know if this is just the way things are or we are missing something :)

gaflach
  • 151
  • 4
  • Hi. I am trying it on a real device, I tried it with Debug but it still having issue:: E/Google Maps Android API(13114): Authorization failure. – Harpreet Jan 14 '13 at 12:31
  • 3
    Uninstalling/reinstalling worked for me after realizing that I had enabled the "Google Maps API v2" instead of the "Google Maps Android API v2" service in the Google API Console. Nice catch gaflach! – suomi35 Feb 28 '13 at 23:45
  • I enabled both "Google Maps API V2" and "Google Maps Android API v2" in console and used android api key the android manifest then maps got displayed – Manju Aug 23 '13 at 06:33
  • Very good point! This reveals why the app didn't work on a device on which I had installed the APK with wrong credentials before! – ercan Dec 16 '13 at 15:23
5

A common reason for this is not registering the correct keys in your Google API console. Specifically, if you are launching directly from Eclipse, your app is not being signed with your release key, but instead with your debug key. Make sure you register both key fingerprints + package names in your console. It helps to check you have your package names correct, too.

Here is a link to how to find your debug certificate fingerprint. Look under the section 'Displaying the debug certificate fingerprint'

iagreen
  • 31,470
  • 8
  • 76
  • 90
  • @lagreen I have surely done all those steps but its not working, it giving "Authorization Failure" Log. – Harpreet Jan 16 '13 at 06:53
  • 1
    @Harpreet are you getting `ConnectionResult.SUCCESS` in response to `GooglePlayServicesUtil.isGooglePlayServicesAvailable(this)`? – iagreen Jan 16 '13 at 17:55
  • @lagreen: Please check the whole question again, I have added the complete code. – Cool Jatt Jan 21 '13 at 07:54
  • This was by far the clearest explanation I found for why maps were not showing up in debug mode but were in production. For most people it would be the other way around, but I had taken over development of an app that was already running in production. I basically had to register the SHA1 fingerprint from my ~/.android/debug.keystore file in the google developer console then put the key from the developer console in my manifest file. After doing this I was able to see the map show up when deploying in debug mode (using Android Studio) – Vijay Boyapati Aug 19 '16 at 20:24
3

Got this problem because I had restriction enabled for my API key in Google Console.

enter image description here

Make sure it is set to none and then try again

Ojonugwa Jude Ochalifu
  • 26,627
  • 26
  • 120
  • 132
2

Please use the Browser key when you download and run the sample project from the internet. Android key will not work in that case and will give this error.

"Could not contact to server. Authorization Failed"

Go to your API Console and get your browser key

Thanks

Let me know if you have any queries regarding Google Maps Api V2

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
1

Please see already posted answer on SO, it will definitely help you..

Need to import project from \extras\google\google_play_services\libproject\google-play-services_lib

Update :

Make sure your device have Google Play Services apk installed and its version should be > 2

Let me know if it works for you..

Community
  • 1
  • 1
moDev
  • 5,248
  • 4
  • 33
  • 63
  • I have checked the Google Play Service version, it 2.0.12. Code is up-to-date from all scenarios and scenes. I just figured it out, its giving LOG :: "01-21 16:14:17.835: E/Google Maps Android API(12168): Failed to load map. Could not contact Google servers." – Cool Jatt Jan 21 '13 at 10:47
0

I figured out the issue that was with registering the application certificate.

What we tried was that we sign the application with our own keystore & alias. But here we exactly need to use the debug.keystore which is already available in SDK.

Harpreet
  • 2,990
  • 3
  • 38
  • 52
0

In that case api key not correct then the google map not showing so follow answer.

Put the below Meta data in android Menifest file first.

 <meta-data
    android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
 <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAU9ShujnIg3IDQxtPrafaf7Q1qOvFVdwNmWc4" />

And then put the right Api key in menifest file.