1

So I've looked over many questions on this issue but have failed to find a solution.

Following is the error I'm currently receiving when I try to use the Google Maps Android API.

02-28 11:17:07.166 7445-7653/com.test.drawernav E/b: Authentication failed on the server.
02-28 11:17:07.166 7445-7653/com.test.drawernav E/Google Maps Android API: Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
02-28 11:17:07.176 7445-7653/com.test.drawernav E/Google Maps Android API: In the Google Developer Console (https://console.developers.google.com)
                                                                           Ensure that the "Google Maps Android API v2" is enabled.
                                                                           Ensure that the following Android Key exists:
                                                                            API Key: ***
                                                                            Android Application (<cert_fingerprint>;<package_name>): ***

Here's my manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.drawernav">

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


    <uses-permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE" />
    <permission
        android:name="com.example.googlemaps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <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.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="@mipmap/logo"
        android:label="Animal Rescue"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".SplashScreen"
            android:label="@string/title_activity_splash_screen"
            android:theme="@style/AppTheme.NoActionBar"
            android:configChanges="keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="portrait" />

        <activity android:name=".SAC" />
        <activity android:name=".FAD" />
        <activity android:name=".HAM" />
        <activity android:name=".BAB">


        </activity>

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="***"/>


    </application>



</manifest>

Here's the Fragment.java for the map

    package com.test.drawernav;


import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;


/**
 * A simple {@link Fragment} subclass.
 */
public class LocateFragment extends Fragment implements OnMapReadyCallback {

    public LocateFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View mapView = inflater.inflate(R.layout.fragment_locate, container, false);

        return mapView;
    }


    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        SupportMapFragment mapFragment = (SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);


    }

    @Override
    public void onMapReady(GoogleMap googleMap) {


    }
}

and the layout.xml for the same

<FrameLayout 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="com.test.drawernav.LocateFragment">


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



    </FrameLayout>

Here's the image showing the enabled Google Maps Android API

Here's the one showing the generated API Key

Zoe
  • 27,060
  • 21
  • 118
  • 148
Devansh
  • 141
  • 2
  • 15
  • Did you double-check the package name / certificate in the Developer Console? – Owais Ali Feb 28 '16 at 06:21
  • Yes. I even tried creating a new project, new code but still the same problem persists. – Devansh Feb 28 '16 at 06:29
  • Just for troubleshooting you could try a new package name + certificate. Also does it work if you remove the package restriction on the key? – Owais Ali Feb 28 '16 at 06:30
  • That does it! Removed the restriction and it's working like a charm! Add your response as an answer so I can upvote :) – Devansh Feb 28 '16 at 06:40
  • Not necessary :) - before you publish to the store though, it would be a good idea to re-enable the restrictions. I'm guessing your certificate fingerprint may be off - you can confirm the value being used with the signingReport Gradle task. – Owais Ali Feb 28 '16 at 06:55
  • How do you remove the package restriction on the key? – LEMUEL ADANE Aug 01 '16 at 06:53
  • 1
    @LemuelAdane In your console, head over to the project you created the key for, go into the settings and under API keys you'll find that there are projects listed which you have allowed to use said key, just remove the projects and you'll be good to go. – Devansh Aug 03 '16 at 14:17
  • @Devansh Hi, did u manage to get a solution for this? I am stuck at the same issue. Please help. – devgeek Aug 25 '17 at 05:01

1 Answers1

1

Try to Put -

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

Instead of-

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="***"/>

and follow- https://developers.google.com/maps/documentation/android-api/map instructions.

NehaK
  • 2,639
  • 1
  • 15
  • 31