Failed to load map. Error contacting Google servers. This is probably an authentication issue
Asked Answered
L

25

31

I search all days and I can't find the answer...

everything is ready but google map still can't show on fragment with tab

I check that I already turn on google map android v2 and right API_KEY

I have no idea what happened!

img

MainActivity.java:

public class MainActivity extends FragmentActivity implements
        ActionBar.TabListener {

    SectionsPagerAdapter mSectionsPagerAdapter;

    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String titles[] = { this.getString(R.string.title_around),
                this.getString(R.string.title_map),
                this.getString(R.string.title_favorite),
                this.getString(R.string.title_achievement), };

        final ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mSectionsPagerAdapter = new SectionsPagerAdapter(
                getSupportFragmentManager());

        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager
                .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
                    @Override
                    public void onPageSelected(int position) {
                        actionBar.setSelectedNavigationItem(position);
                    }
                });

        for (int i = 0; i < titles.length; i++) {
            actionBar.addTab(actionBar.newTab().setText(titles[i])
                    .setTabListener(this));
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) {
        mViewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab,
            FragmentTransaction fragmentTransaction) {
    }

    @Override
    public void onTabReselected(ActionBar.Tab tab,
            FragmentTransaction fragmentTransaction) {
    }

    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // TODO 在這邊決定哪個位置要給什麼 View(Fragment)
            Fragment fragment = null;
            // TODO 建議先在之前就初始化好 4 個 Fragment
            switch (position) {
            case 0:
                fragment = new AroundFragment();
                break;
            case 1:
                fragment = new MapsFragment();
                break;
            case 2:
                fragment = new FavoriteFragment();
                break;
            case 3:
                fragment = new AchievementFragment();
                break;
            default:
                break;
            }

            return fragment;
        }

        @Override
        public int getCount() {
            return 4;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            // TODO 在這邊決定每一個 View 的 title
            switch (position) {
            case 0:
                return getString(R.string.title_around);
            case 1:
                return getString(R.string.title_map);
            case 2:
                return getString(R.string.title_favorite);
            case 3:
                return getString(R.string.title_achievement);
            }
            return null;
        }
    }

}

MapsFragment.java:

public class MapsFragment extends Fragment{
    static final LatLng NKUT = new LatLng(23.979548, 120.696745);
    private GoogleMap map;
    SupportMapFragment mMapFragment;
    public MapsFragment() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.map_fragment,container, false);

        map = ((SupportMapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();

         mMapFragment = SupportMapFragment.newInstance();
         FragmentTransaction fragmentTransaction =
                 getFragmentManager().beginTransaction();
         fragmentTransaction.add(R.id.map,mMapFragment);
         fragmentTransaction.commit();

        return rootView;

    }
}

Map_fragment.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout> 

Manifest.xml:

<!-- Google Map -->
<permission
        android:name="com.jertt.yummymap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
<uses-permission android:name="com.jertt.yummymap.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"/>
<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<!-- end -->
    <!-- Google Map API Key -->

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="key" />

    <!-- end -->

Solution:

I found the solution!!!

If you use private keystore to apply API_KEY. You cannot upload and install application with eclipse.

You need to upload .apk file to your device by yourself and install it!

Thanks Tarsem and srikanth gr help!!

Leyva answered 16/7, 2013 at 4:20 Comment(5)
Have u added google play lib in your project ????Periodate
yeah,see this,I added imgur.com/tH5dzZcLeyva
I found the solution!!! If you use private keystore to apply API_KEY. You cannot upload and install application with eclipse. You need to upload .apk file to your device by yourself and install it! Thanks Tarsem and srikanth gr help!!Leyva
What package did you use on the Google API to associate the key with? I have an app with it full screen working, but my tabbed view version is not working. I know my key is valid from the full screen version working. Any ideas?Houlberg
https://mcmap.net/q/470254/-failed-to-load-map-error-contacting-google-servers-issue-with-android-google-maps-api-v2-duplicatePhosphine
H
68

it sounds like you have problem with your API_KEY which is obtained from Google API Access ,so verify your API_KEY , certificate fingerprints and package name

also use this inside <manifest>

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

and also verify: <meta-data .... > should be inside <application> tag


PS.

1. Also try by adding following Permission

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

2. After changing API key in AndroidManifest.xml Must Clear Application Data

To Clear Application Data :

Either Go to Settings>Application Manager>Select Your Application > Click on Clear Data

Or Must Uninstall The Application before installing it ! Note Don't Re-install unless you Completely Uninstall the Application in order to clear its Data completely

Hamate answered 16/7, 2013 at 4:34 Comment(5)
Oh my! I found the problem!!Leyva
If you use private keystore to apply API_KEY. You cannot upload and install application with eclipse. You need to upload .apk file and install it by yourself! Thanks Tarsem and srikanth gr help!!Leyva
The key part for me was that the application data has to be cleared if the API key changes. Thanks!Quipster
For me this was very usefull, but the best was Clear Application Data with: Go to Settings>Application Manager>Select Your Application > Click on Clear DataCounterblow
I came here with the same question. The problem was - I changed package name of my app, but did not mirror the change in my API key preferences at Google API Console. Argh, irritating stuff :)Verticillate
C
35

I spent so much time, there are too many similar questions.

I tried to add own permission, WIFI_STATE permission, but the real problem was in application data.

After you change API key in manifest, you MUST "Clear data" of your application (or completely re-install).

This helps me and I hope this post will help somebody.

Camire answered 30/7, 2013 at 13:1 Comment(0)
C
10

My problem was solved by adding permission to the manifest:

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
Christine answered 8/8, 2013 at 11:44 Comment(2)
It is incredible how it is fuzzy trying to understand how some components work in Android. It seems magic! Thank you dude for the solution, it really helped me.Trudietrudnak
Note that this permission is no longer necessary as of May 2014.Mountford
S
6

I have the same issue, and my problem was that I didn't activate the service in the console:

  1. Go to console: https://code.google.com/apis/console/
  2. Go to services section
  3. Enable Google Maps Android API v2
  4. Follow all the steps in the documentacion
Spartan answered 23/8, 2013 at 8:10 Comment(0)
A
5

If you are have a problem with auth, check in Logcat your package name. If you use Android Studio check out your build.gradle. When file contains applicationIdSuffix '.dev'. You should add .dev to your package name.

e.i. package name is:

com.company.main

In API console write

...9S.ME.DA.FE;com.company.main.dev

Austriahungary answered 12/9, 2014 at 22:3 Comment(2)
Thanks - not the exact problem, but I had a different mock service build flavour which resulted in a different package name.Tiddly
I love you! 3 Days searching for a solution and you saved me! Thanks this solved my problem :)Jack
G
4

After doing everything that people said to like checking my manifest, adding permissions, making a new key with the sha1 in eclipse etc. and it still not working I just did:

adb uninstall com.example.hellomap

and then running through eclipse again. It seemed like the device wasn't getting completely new data. Hope this helps.

Gyrate answered 12/9, 2013 at 21:23 Comment(2)
Thank you for your a tiny but powerful solution. haha! I had the same problem and solved with the same way.Buckboard
Oh! I'm gonna add some information. This problem happened on Gingerbread but not on ICS, JB.Buckboard
A
2

I was able to use the debug key and load from eclipse. I was missing the following permission in my AndroidManifest.xml

uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"
Asphyxiant answered 26/10, 2013 at 14:3 Comment(0)
F
1

After reviewing a lot of cases and successfully run the maps, these things are important to have in mind:

  • Use android api 17, booth emulator and project
  • Reference the google services
  • Use the android support if needed
  • Use the following order in libraries: src, gen, google apis, android support, dependencies and private libraries
  • Use a correct api key
  • Clear data, re-install app.
Fortyish answered 30/7, 2013 at 22:27 Comment(0)
D
1

I had configured many services including Google Maps API v2 (not Google Maps Android API v2) which was conflicting. After removing the unwanted service and generating a new key, including in the manifest, clean install, map appeared on the device.

Decosta answered 23/8, 2013 at 13:2 Comment(1)
I didn't have to generate new keys. At least not in debug/test mode. ymmvDissonancy
S
1

I have fixed the issue by giving the permission in the manifest

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
Stream answered 13/12, 2013 at 12:7 Comment(0)
S
1

I was facing the same issue in Android Studio. Google maps would not show up when connected to android debugger.

I fixed it by adding the SHA1 fingerprint for debug keystore located in ~/.android/debug.keystore. I think this keystore is generated by default (not sure though).

The following command in Terminal worked in order to get the SHA1 fingerprint:

keytool -list -v -keystore ~/.android/debug.keystore 

When it asks for password, don't type anything just press enter. (Worked in my case)

Add this fingerprint to your API key for Android applications in developer console.

Cheers!

Sculptress answered 24/11, 2014 at 12:11 Comment(0)
S
0

In my case what worked is that I had to install it via command line :

adb install /path/to/app/MyApp.apk

Secretarygeneral answered 23/8, 2013 at 9:41 Comment(0)
J
0

All you have to do is: use the debug key in your code; uninstall the app; install the new app with the debug key.

Jocelin answered 20/9, 2013 at 20:37 Comment(0)
G
0

In case, if nothing(above stated) works, there is a good possibility that you are using wrong debug.keystore file for generating fingerprint. If you have multiple debug.keystore files in your machine, ensure that you are using the correct debug.keystore to generate the SHA1 fingerprint.

Goby answered 8/10, 2013 at 12:23 Comment(0)
A
0

Many of these helped me but the main issue was that I didn't have the correct signing. I am using Xamarin and hence it's not built into the IDE, so when I would generate the key using keytool, it would never get into the application. I had to add the following in my .csproj file:

<PropertyGroup>
   <AndroidKeyStore>True</AndroidKeyStore>
   <AndroidSigningKeyStore>maps.keystore</AndroidSigningKeyStore>
   <AndroidSigningStorePass>android</AndroidSigningStorePass>
   <AndroidSigningKeyAlias>androiddebugkey</AndroidSigningKeyAlias>
   <AndroidSigningKeyPass>android</AndroidSigningKeyPass>
</PropertyGroup>
Albaugh answered 1/5, 2014 at 3:58 Comment(0)
D
0

The error for me was that I was running the debug configuration when I just have added the release configuration to Google Developers Console. So, I followed these steps:

  1. Get the sha1 for your debug keystore using:

    keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

  2. Goto https://console.developers.google.com and add sha1+package.

  3. Add your API_KEY to your AndroidManifest.xml file.

Demean answered 13/8, 2014 at 11:56 Comment(0)
M
0

In IntelliJ ..if you sure that you SHA1 key is correct, API key is not missing,

Permission and any setup in Manifest is correct.

Maybe you have to Right Click on your Google-Play-Services-lib and Compile it again

I have done all the things and this does the trick for me.

Mcewen answered 20/8, 2014 at 14:54 Comment(0)
P
0

My the weirdest mistake I have done so far was obtaining SHA1 code from debug.keystore.

I though it has no password, but the password was android

Not sure if it helps anyone, but it helped me. Plus use a full package name, you can find it in java source code file. For example, there is mine: com.example.erikas.mapsdemo ( looks like: package com.example.erikas.mapsdemo; )

So when you try to get a API key, use input like this:

XX:XX:XX:XX:XX:17:C9:22:BB:BD:7C:87:12:83:2D:XX:XX:XX:XX:XX;com.example.erikas.mapsdemo

So my own mistake was a wrong SHA1 code and wrong package. But fortunatelly - I figured it out after 2 days of headache! :D

Parthen answered 9/9, 2014 at 8:54 Comment(0)
C
0

When debugging, I needed to add an additional API key for the ~/.android/debug.keystore

This keystore is setup automatically for you and the password is "android"?

Corrinecorrinne answered 3/10, 2014 at 17:15 Comment(0)
E
0

I faced the same problem,Have solution for this, I tried to create debugging api key from different google account with same package name. Step to clear the bug: 1.Remove the unwanted api key with same package name in different google account. 2.Please Maintain the Api key generation in single account for solve this problem. Thank you. Try this.

Egin answered 24/10, 2014 at 19:37 Comment(0)
S
0

I was stuck on this question for about a week. So I started to use real device. But one day I try to set Custon debug keystore (Eclipse, Window -> Preferences -> Android -> Build -> Cusom debug keystore) to the same as default one. And all become to work. Of course, first I've got a key at a google console.

Hope this will help!

Siana answered 5/12, 2014 at 1:15 Comment(0)
Z
0

I was facing the same problem. I have tried several solutions - none worked for me. What worked for me was generating a new API key and CLEARING the DATA of the Google play service on my device.

Zeitgeist answered 30/4, 2015 at 16:57 Comment(0)
V
0

Check list: 1. Check for permission in Android Manifest for READ_GSERVICES

< uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

  1. Clear application data if you have done some changes in the manifest.

  2. Check debug.keystore in your .android folder.

    My Issue got resolved just by replacing debug.keystore located at .android folder by debug.keystore of your app.

Visigoth answered 5/5, 2015 at 10:19 Comment(1)
There is already a highly accepted answer that covers what you said.Maritime
O
0

I also faced same issue, while using Android Studio.

I have referred all the solutions, but still it was not working.

The problem was I have changed my package name after initial project setup. Changing package name was reflected in Manifest, but in build.gradle file old package name was there.

As soon as, I have changed package name in build.gradle, Map starts working.

Hope it helps someone.

Oneal answered 15/5, 2015 at 6:56 Comment(0)
A
0

I had the same problem. I checked Logs and there was said "Authentication failed on the server". So, I checked www.console.developers.google.com and found out that the package name was incorrect. (This package name was automatically written) I wrote it correctly and everything works good.

Allure answered 3/1, 2016 at 21:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.