Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps V2 - Authorization failure, I can't display map

I'm trying display a map on my app but I can't display, I's impossible for me...

My steps:

  1. Install "Google play services" from SDKManager.

dib1

  1. Add library from Project

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "prueba.mapas.alvaro.myapplication"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.87'
}

Add Library to AndroidManifest.xml too.

Manifest (part)

 <application

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

......

 </application>
  1. Get SHA1

dib2

  1. Go to "https://code.google.com/apis/console/b/0/?noredirect" ato get API Key.

fdf

  • Package name on Android Studio

dib4

  1. Modify AndroidManifest.xml with permissions.

    <permission
        android:name="prueba.mapas.alvaro.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="prueba.mapas.alvaro.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"/>
    
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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>
    
        <meta-data android:name="com.google.android.gms.version"
                   android:value="@integer/google_play_services_version" />
    
        //api key
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyD1UolEb1tDMe6qB5BUF5orFzc3CDtvJYg"/>
    
    </application>
    

  2. Create my Layout map_activity.xml

  3. Create my principal class MainActivity.class

    public class MainActivity extends ActionBarActivity {

        @Override
    
        protected void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map_activity);
    
            MapFragment mapFragment = (MapFragment) getFragmentManager()
                    .findFragmentById(R.id.map);
        }
    }
    
  4. Connect my Device and it's reports that error and on my device always appear White screen.

enter image description here

NOTE: ALWAYS I CLEAR DATA FROM MY APP ON MY DEVICE, UNISTALL AND INSTALL AGAIN, NOT WORKS

UPDATE

I have enable Google Maps V2 on console

enn

Any suggestions?

UPDATE - SOLUTION

Solved, I put on the Manifest the "Key for browser apps (with referers)" instead of the "Key for Android apps (with certificates)" from the Google API Console

like image 733
Aspicas Avatar asked Mar 18 '23 00:03

Aspicas


2 Answers

SOLUTION:

Put on the Manifest the "Key for browser apps (with referers)" instead of the "Key for Android apps (with certificates)" from the Google API Console

like image 100
Aspicas Avatar answered Mar 29 '23 23:03

Aspicas


I checked your code. Sounds like well. But try this .

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

Use FragmentActivity

 public class YourActivity extends FragmentActivity {

   GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.your_activity);
        map =((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.iqamah_map)).getMap();

    }
}

Update your build.gradle

  compile 'com.google.android.gms:play-services:5.0.89'
like image 22
IntelliJ Amiya Avatar answered Mar 30 '23 00:03

IntelliJ Amiya