Search code examples
javaandroidandroid-fragmentsactionbarsherlockgoogle-maps-api-2

What's wrong with google map API v2?


This issue is common BUT I didn't find a solution on google, or stackoverflow (4days of research...)

Here is the thing :

I need to display a full screen google map, which i ve already done several times in other application i've developped. BUT here i can't get it to work for an unknow reason !

The warning and the error i get when i open the SherlockFragmentActivity which contains the map :

The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.

Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

Here i'll explain how i did things in detail and post some code :

LIBRARY IMPORT :

Last version of Google play services imported in eclipse as library (checked) In the project the google play services are imported as library in properties (like ABS)

MANIFEST :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="pck name"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <permission
        android:name="com.company.pckgname.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <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_NETWORK_STATE" />
    <!-- LOCATION -->
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <application
        android:name="app variable name"
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:theme="@style/Theme.Styleapp" >
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="api key" />

        <activity
            android:name=".ActivityLauncher"
            android:configChanges="orientation|screenSize"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.Sherlock.NoActionBar" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

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

... activities...

        </application>

    </manifest>

MAP LAYOUT :

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.company.pckgname.TransparentSupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

ACTIVITY :

public class ActivityGoogleMap extends SherlockFragmentActivity implements OnInfoWindowClickListener {

        GoogleMap                   _googleMap;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // ABS
        ActionBar bar = getSupportActionBar();
        bar.setTitle(R.string.tle_map);
        bar.setDisplayHomeAsUpEnabled(true);
        // MAP
        _googleMap = ((TransparentSupportMapFragment) getSupportFragmentManager().findFragmentById((R.id.map))).getMap();

 //the map should still display at this point
        }
    }

And so that's it, the main code is here

The map was working up until now, i didn't do nything with the code map related...

I tried to regenerate a debug key on the google console, change the permissions .. etc i am out of idea !!!!


Solution

  • After changing the API key in AndroidManifest.xml you must clear application data.

    To clear application data do one of the following:

    • Go to Settings > Application Manager > Select Your Application > Clear Data
    • Uninstall the application before re-installing it.