6

I'm trying to display a google maps in a very simple application (a new project with just a google maps Activity) the manifest has the permissions:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ivan.pruebamaps">

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


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

<activity
    android:name=".MapsActivity"
    android:label="@string/title_activity_maps">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

    </manifest>

I have a valid key in @string/google_maps_key.

The mainActivity it's untouched, the same as it's created in android studio.

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}


@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}

The same happens with the layout file activity_maps:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.ivan.pruebamaps.MapsActivity" />

This is my gradle file if that helps :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.ivan.pruebamaps"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.google.android.gms:play-services-maps:10.2.0'
    testCompile 'junit:junit:4.12'
}

When i execute the app i just get a screen with a blank screen and the Google logo in the left bottom corner. I'm trying in a emulated nexus 5, and in a samsung galaxy s6, neither works.

Asdemuertes
  • 313
  • 3
  • 6
  • 19
  • 2
    The "Blank Map" issue is always due to a bad API key. Check the logs, there should be an error in there. – Daniel Nugent Mar 24 '17 at 23:56
  • Indeed, I'm getting a message in the log telling me to check if my key exists. Which is incredible because i tried the exact same project in a different pc with sdk 24 and it worked. I'm astounded. – Asdemuertes Mar 25 '17 at 00:01
  • In my case, it showed on a real device but was blank on an emulator. It was not an API key problem as I have tried a new key. I looked into the log and there was a message, > E/Google Maps Android API: Google Maps Android API v2 only supports > devices with OpenGL ES 2.0 and above I remembered that AS had complained about my GPU (Intel HD) before, so I tried several OpenGL settings in the emulator's settings, but none of them worked. Perhaps I would have to install a dedicated GPU or change the CPU. – Damn Vegetables Dec 16 '17 at 14:01

6 Answers6

10

It sounds like the API key you're using was generated on a different machine, which has a different debug keystore.

You will need to add the SHA1 fingerprint for the debug keystore for each dev machine you use to your API key in the developer console.

In addition to that, once you're ready to make a signed release build, be sure that you use the SHA1 fingerprint for your release keystore in the API key that goes into the release version of the google_maps_api.xml file. See here for more info.

Community
  • 1
  • 1
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
1

Try installing google play services through android sdk and try again.

This might help How to download Google Play Services in an Android emulator?

Community
  • 1
  • 1
sai
  • 434
  • 5
  • 13
  • I already had it installed in the s6 terminal.and in the emulator i'm not having any error when trying to launch the app. – Asdemuertes Mar 24 '17 at 23:50
1

In my case, the problem was the API key I guess. As soon as I changed my API key with a new one that I generated the map was back online.

double-beep
  • 5,031
  • 17
  • 33
  • 41
1

This issue is because of API key .

Steps :

  1. Go to your Google API Dashboard .
  2. Navigate to credentials ,
  3. look for Android key (auto created by Google Service) .
  4. use this key in your manifest.xml

metis
  • 1,024
  • 2
  • 10
  • 26
Farry
  • 21
  • 3
0

if you use avd(Android virtual device) for your app, in some case, it will be not working

use real device it works for me

I use googlemap fragment in main activity extends appcompatactivity it works!

0

Had the same problem and solved it by uninstalling the app completely from the device I was debugging on, and installing it again afterward.

Idan
  • 137
  • 1
  • 9