Search code examples
androidandroid-mapviewtilessha1api-key

Why does MapView show grey tiles and not the map?


Ok, so I got my SHA1 fingerprint by creating a batch file. After that, I went to the "Services" page and enabled Google Maps API v2 and v3. I also went to the "API Access" page and created a new Android Key with the SHA1;PACKAGENAME. After this, I went to my project folder and added the following code:

<permission
    android:name            = "com.example.test.permission.MAPS_RECEIVE"
    android:protectionLevel = "signature" 
/>

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

<uses-permission android:name="com.example.test.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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-library android:name="com.google.android.maps" />

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

I also created an XML file and pasted the following code:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
    xmlns:android           = "http://schemas.android.com/apk/res/android"
    android:id              = "@+id/mapview_MV"
    android:layout_width    = "fill_parent"
    android:layout_height   = "fill_parent"
    android:clickable       = "true"
    android:apiKey          = "APIKEY"
/>

After compiling and running the project on my HTC One X+, I saw nothing more than bunch of grey tiles. I also tried to use a MapView in code as shown below:

/********************************************************************
* ONCREATE                                                          *
********************************************************************/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView( R.layout.general_layout );

    MapView mapView = new MapView( GamePage.this, "APIKEY" );
    MapController mc = mapView.getController();
    String coordinates[] = {"1.352566007", "103.78921587"};
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);

    GeoPoint p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6) );

    mc.animateTo(p);
    mc.setZoom(17); 

    FrameLayout fl = ( FrameLayout ) findViewById(R.id.general_frameHolder_FL);
    fl.addView(mapView);
}

I get to see the following error:

Couldn't get connection factory client

Can anyone tell me what the hell I'm doing wrong!?


Solution

  • I found a solution for the problem. What I needed to do was delete the Google Play Services in the SDK Manager and reinstall it, because I missed lots of packages for some reason. Thanks to Fido, I found out that MapView isn't supported in Google Maps Android v2 API and read the whole introduction at: https://developers.google.com/maps/documentation/android/start#specifying_permissions.

    After that, I also found a site where you can solve the NoClassFoundError at: http://www.user.tu-berlin.de/hennroja/tutorial_fixing_java.lang.NoClassDefFoundError%20com.google.android.gms.R$styleable.html

    It took me +- 5 hours to solve this freaking issue with the new Google Maps API.