3

I tried to test Google Maps and created a new project, got API key from API console. Everything was working, no problems. But when I tried to add Google Maps activity in to the working project, by making this activity as a luncher, with above steps, now I am getting the following errors:

Google Maps Android API: Authorization failure. Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map. 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: AIzaSyA5iBkfmlihtkh2Xc6T61v109eFJ3OGZrE Android Application (;):

AndroidManifest.xml

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

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:name=".AfexApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".activities.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>
        <activity
            android:name=".activities.LoginActivity"
            android:label="Tizimga kirish" />
        <activity
            android:name=".activities.RegistrationActivity"
            android:label="Ro&apos;yxatdan o&apos;tish" />
        <activity android:name=".activities.Tovar_description_Activity" />
        <activity android:name=".activities.OmborActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        <activity android:name=".models.Switch_Mode" />
        <activity android:name=".activities.SettingActivity" />
        <activity
            android:name=".AddressActivity"
            android:label="@string/title_activity_address"
            android:theme="@style/AppTheme" />
        <activity android:name=".AddressAddingActivity" />
        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".activities.GoogleMapActivity"
            android:label="@string/title_activity_google_map">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

2 Answers2

1

Enable the Maps API in Google Developers Console (https://console.developers.google.com/).

Raj
  • 2,997
  • 2
  • 12
  • 30
  • 1
    I've already did it. But, still map is not shown. Only on the left-bottom side Google logo is appearing – Tursunboy Tojiev Jul 12 '18 at 14:30
  • Have you given location permissions in mobile ?? – Raj Jul 12 '18 at 14:31
  • Yep. Also, as I told Google Maps is working when I create it as a new project. But when I am trying to add it to my another project with some activities, Google Maps is not working – Tursunboy Tojiev Jul 12 '18 at 14:52
  • If you have restricted your api key with the previous projects package name then it will not work for your new projects. You have to generate a new api key. Try it and then let me know. – Raj Jul 12 '18 at 15:45
  • I've tried. I deleted all my projects and create new one from given link in google_maps_api.xml. But still it is not working – Tursunboy Tojiev Jul 13 '18 at 10:14
  • I have the same problem and still not able to make it work – Manuelarte Sep 26 '19 at 10:09
0

That is because you made a project with map activity but you are trying to add the activity into another project.

You probably used the package name of map activity project in the Maps API in Google Developers Console.

The solution is, create a new map api key with your actual project's package name then use the API key to your project.