0

I am trying to create a basic google map activity, but when i try to run it to my smartphone, I get a blank activity (click here to see a screenshot of the issue). What im doing wrong? It is something wrong with my API Key, maybe?

AndroidManifest.xml

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

    <application
        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.gms.version"
            android:value="@integer/google_play_services_version"/>

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

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
</manifest>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.SupportMapFragment" />

MainActivity.java

import com.google.android.gms.maps.GoogleMap; 
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.MarkerOptions; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity;

    public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
            mapFragment.getMapAsync(this);
        }

        @Override
        public void onMapReady(GoogleMap map) {
            map.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
        } }

Thanks in advance.

Neuron
  • 5,141
  • 5
  • 38
  • 59
ferrvn
  • 25
  • 1
  • 1
  • 4
  • Please don't post links to images on external websites. The images might get taken offline, rendering your post useless to all people coming here in the future.. – Neuron Apr 09 '18 at 22:13

5 Answers5

1

The problem usually happens when there is some problem with the wy you defined Google Maps permissions or from a bad configuration of the allowed API in the Google API console.

Make sure that you turn on the Google Maps Version 2 for Android in the console and not the one for web. Also please check your permission, here's a related SO ticket which encounter blank screen: Android Google Map API V2 Blank Screen

Here's a sample demo app for Google Maps Android API v2: https://github.com/googlemaps/android-samples

Community
  • 1
  • 1
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
0

First ensure you have enabled the Google Maps Android API v2.

Then see this answer and this one.

Community
  • 1
  • 1
Emzor
  • 1,380
  • 17
  • 28
0

I think you missing out the API key. I assume that you use android studio (maps activity). After creating a project , you have to create an API key for your project and that needs to be linked in the project. To create an API key, you have to visit a link provided in google_maps_api.xml (from your project).

Once you created your API key, then you have to insert that API key in the google_maps_api.xml file (may be the in last line where asks for your key).

Follow this pic for reference

0

I had same Problem. To solve it you need to check your permissions

To do this:

  1. Go to the google cloud console
  2. Go to the Enable APIs and Services section
  3. Enable the Google Maps Android API
Srini
  • 1,619
  • 1
  • 19
  • 34
0

After following this Map With Marker still I was getting blank screen. Then you need to again re-create the new API KEY and also enable MAPS SDK for Android. Then you need to restrict your key for specific use mentioning platform and API Restriction.

Mohit Kumar
  • 41
  • 1
  • 7