ariets
ariets

Reputation: 4268

Map won't show with Android Maps API v2, Gradle and Android Studio

I am attempting to add The Maps API v2 for Android to my project that is being built in Android Studio. I am adding the Google Play Services through the build.gradle file and maven (it is being imported through the Google Repository in the SDK Manager). I add the following to my build.gradle file inside of my project:

compile "com.google.android.gms:play-services:3.1.36"

This works near perfectly. I am able to use the APIs in code and reference them in XML. For example, I am using LocationClient to retrieve the users location just fine; I can add com.google.android.gms.MapView to an XML file and it builds and runs perfectly.

The issue is that the map will not display. Now, I have added the following to my manifest:

<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 ...>


    <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="[MY API KEY HERE]"/>

</application>

I obtained the API key through the use of the debug certificate; I have turned on the "Google Maps Android API v2" in the API Console. Everything appears to be set up just fine, but the map still will not load. Any help?

Upvotes: 2

Views: 1747

Answers (1)

powerj1984
powerj1984

Reputation: 2226

Checking the documentation here:

Users of this class must forward all the Activity life cycle methods - such as onCreate(), onDestroy(), onResume(), and onPause() - to the corresponding methods in the MapView class.

If you neglect this step you will run into the issue where the map will not load.

Upvotes: 4

Related Questions