androidgoogle-mapsandroid-studiomapactivity

Errors with Google API in android application utilizing MapActivity


I've tried and tried and tried to figure this problem out. I've searched everywhere and I haven't found a solution yet. I understand that there are many forums on this topic, but none have helped me come up with a solution.

The problem I'm having is that when I run my android application, in the emulator, the area for the map comes up only with grey tiles. I've read online that the problem is most likely the Google API key, but I've tried multiples way to generate it (Used the Android Studio Terminal to obtain SHA1, I had Android studio generate a link to google so it can automatically create the key).

I'm hoping someone can help me out, I'm pretty desperate here!

Here's my Activity class package com.bignerdranch.android.taskmanager;

import android.os.Bundle;

import com.google.android.maps.MapActivity;

public class AddLocationMapActivity extends MapActivity {

    public static final String ADDRESS_RESULT = "address";

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.add_location);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    @Override
    protected boolean isLocationDisplayed() {
        return true;
    }

}

This is the layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
        android:id="@+id/location_title"
        .../>

    <EditText
        android:id="@+id/task_address"
        .../>

    <Button
        android:id="@+id/map_location_button"
        .../>

    <com.google.android.maps.MapView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/map_location_button"
        android:layout_above="@+id/use_this_location_button"
        android:clickable="true"
        android:apiKey="AIza.................................." />

    <Button
        android:id="@id/use_this_location_button"
        .../>

</RelativeLayout>

Then, this is the manifest file:

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

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <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" />

    <application
        android:name=".TaskManagerApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIza..........................." />
        <activity android:name=".ViewTasksActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".AddTaskActivity"
                  android:text="@string/add_task"/>
        <activity android:name=".AddLocationMapActivity"
                  android:text="@string/add_location_to_task"/>

        <uses-library android:name="com.google.android.maps" />
    </application>

</manifest>

Then the build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:24'
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.bignerdranch.android.taskmanager"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
    compile 'com.google.android.gms:play-services-location:10.0.1'
}

And lastly, this is what is generated by the Monitor:

12-02 22:37:10.351 22387-22537/com.bignerdranch.android.taskmanager W/System.err: IOException processing: 26
12-02 22:37:10.351 22387-22537/com.bignerdranch.android.taskmanager W/System.err: java.io.IOException: Server returned: 3
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err:     at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err:     at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err:     at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err:     at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err:     at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err:     at java.lang.Thread.run(Thread.java:818)

I WOULD BE FOREVER GRATEFUL TO THE PERSON WHO CAN HELP ME FIGURE THIS PROBLEM OUT! Grey tiles instead of map


Solution

  • The map that you're using com.google.android.maps.MapView is a v1 of Google Map API. Unfortunately, it is officially deprecated.

    You should use the new version of Google Maps API which is Version 2

    Here's a tutorial for Google Map V2