Maps Android Studio is not displayed

8

I have been learning how to use Maps in android studio. The project compiles OK, but when I open the app on the mobile you can not see anything, just the word google on the bottom.

already create and add the api key. What may be happening?

<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" />
<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="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SecondActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <!--
         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="AIzaSyDAEkJrbbqVfGLD7tWhksHRceh8Wqi-j8o" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps"></activity>
</application>

    
asked by Alejandro Echeverria 01.04.2016 в 17:15
source

3 answers

5

If your map is not displayed correctly, it is important to check within LogCat , for example you could have this message:

  

Ensure that the "Google Maps Android API v2" is enabled. Ensure that the following Android Key exists:
    API Key:
    Android Application (;):   10: 6D: D9: 34: 96: A6: 1C: 5A: 45: 5F: 2C: C5: F7: FA: A5: E0: A2: D3: 58: E0; com.pollitos.testapplication

To enable the LogCat : from the menu: Tools - > Android - > Android Device Monitor and there you select the tab "logCat "where information related to your application is displayed.

The main reason why the map is not displayed is because it does not have the correct KEY API or the API is not enabled.

Reviewing the steps again to correctly configure Google Maps in an Android application:

We go to the development console to enable the API de Google Maps

link

We look for Google Maps Android API and go to the option " Credentials "

We select: Create Credentials > API KEY > Android Key

We add a description and then add the application package and the certificate SHA-1 that appears in the LogCat , it is important to add the correct package since the permissions to visualize the map are assigned depending on the package and keystore used (certificate SHA-1 ).

When you create the Key API with these values you will get a dialog with the value of your KEY API to configure in your AndroidManifest.xml

when setting this value within your Manifest.xml

 <!--Google MAP API key-->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyAx7OiP9d4py5lWMOFfIrR63a9K-ikLTtw" />
</application>

You can easily upload Google Maps to your application:

It is very important to also comment, that the API KEY depends on the Keystore with which the application is generated. In my case I have a KEY API generated from SHA-1 of Kesytore debug and other API KEY generated from Keystore with which the application is signed in production.

  • If you are working in development, get the SHA-1 from the development Keystore located at:

C:\Users\<user>\.android\debug.keystore

Register it, get the KEY API and configure it in your project.

  • In production you must obtain the SHA-1 from the Keystore with which the application is signed for the Google Playstore, register it, obtain the KEY API and configure it in the project.
answered by 01.04.2016 / 19:35
source
2

Preparations for Android Studio

Following the steps of the Android Maps Guide I have been able to extract the prerequisites to use the Google Maps service.

Install the Google play Services of the SDK Manager Create apikey of Google Places API for Android in the console: console developer

Add the dependencies in file app.graddle

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

Create values / google_maps_api.xml

<resources>
    <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
        <!-- código de la APIKEY
        https://developers.google.com/maps/documentation/android/start#get-key
        -->
    </string>
</resources>

apply permission ACCESS_FINE_LOCATION in file Manifest.xml to be able to use google maps

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

And define new activity

<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"></activity>

Create the layout layout / activity_maps.xml

<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.testsettings.app.testgooglemaps.MapsActivity" />

The activity where you want to use the google maps element must inherit from FragmentActiity and load the interface OnMapReadyCallback

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);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng myLocation = new LatLng(13.0810, 80.2740);
        mMap.addMarker(new MarkerOptions().position(myLocation).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(myLocation));
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(myLocation.latitude, myLocation.longitude), 11.0f), 1500, null);

    }
}
    
answered by 06.04.2016 в 18:34
0

I have the same problem, but it does not charge me when the device has only GPS enabled, when the "Location mode" is in "high precision mode" with networks and Wifi, the map loads perfectly .. That was not your problem but I'll leave it in case someone is going through the same thing as me.

    
answered by 15.11.2017 в 18:21