0

I have been in this problem for a day now. I have followed and even changed to exactly alike from the tutorials. I can't seem to understand what's the problem. Everytime I run it to my device the map doesn't load and in LogCat it says:

05-08 16:21:02.130: E/Google Maps Android API(28021): Failed to load map. Could not contact Google servers.

Here's my layout main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    map:cameraTilt="45"
    map:cameraZoom="14" >

<fragment 
    android:id="@+id/the_map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.SupportMapFragment"
/>
</RelativeLayout>

Here's the AndroidManifest.xml:

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

<permission
  android:name="com.example.permission.MAPS_RECEIVE"
  android:protectionLevel="signature"/>
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.example.gmapactivity.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<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"/>

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="com.example.gmapactivity.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="the-generated-api-key-from-console" />   
</application>

</manifest>

Finally my MainActivity.java:

package com.example.gmapactivity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

I have deleted my android key and regenerated from my debug keystore which is also the default debug keystore in Eclipse. Used the generated SHA1 key to the Google API with the service Google Maps Android API v2 and applied the API key to the manifest. Still no luck. I'd be very grateful if someone could suggest a solution.

Compaq LE2202x
  • 2,030
  • 9
  • 45
  • 62
  • Maybe a dump question, your device have an active and working internet connection? – sandkasten May 08 '13 at 08:00
  • have you added the key in the `android:value` ?The manifest you provided has no key in it or is it just for explanatory purpose here? – Abx May 08 '13 at 08:06
  • I have already applied the generated API key from the console to the android:value. I just didn't display it for security purposes. – Compaq LE2202x May 09 '13 at 10:24

4 Answers4

0

You have applied wrong permissions:

<permission
  android:name="com.example.permission.MAPS_RECEIVE"
  android:protectionLevel="signature"/>
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.example.gmapactivity.permission.MAPS_RECEIVE"/>

Should be this:

<permission
 android:name="com.example.gmapactivity.permission.MAPS_RECEIVE"
 android:protectionLevel="signature"/>
<uses-permission android:name="com.example.gmapactivity.permission.MAPS_RECEIVE"/>

And in your layout file: Those parameters:

map:cameraTilt="45"
map:cameraZoom="14"

Should be applied to the fragment and not to the RelativeLayout.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • Transferring `map:cameraTilt="45" map:cameraZoom="14"` would give error 'Unexpected namespace prefix "map" found for tag fragment' – Compaq LE2202x May 09 '13 at 10:34
  • this because you have to move this line: xmlns:map="http://schemas.android.com/apk/res-auto" to the fragment section as well and not in the main RelativeLayout. – Emil Adz May 09 '13 at 10:59
  • I've done it before but will add another error for `xmlns:map="http://schemas.android.com/apk/res-auto"` which is `Unexpected namespace prefix "xmlns" found for tag fragment` – Compaq LE2202x May 09 '13 at 11:15
0

Have you added your package to the API Access in Google APIS?

You should have something similar to this in the "Edit allowed Android apps":

FD:F4:....:D2;com.example.gmapactivity

The first parameter is as you said the SHA-1 of the signing key and the second is your application package

Also, from your code, you are loading the main.xml to the Options menu, not the view of the fragment (which is activity_main.xml). Change your

setContentView(R.layout.activity_main);

to

setContentView(R.layout.main);
Corbella
  • 1,791
  • 14
  • 24
  • I did apply my package but until com.example only: `FD:F4:....:D2;com.example` not `FD:F4:....:D2;com.example.gmapactivity` Furthermore, I do not have main.xml in my layout so it would cause error `main could not be resolved or is not a field` – Compaq LE2202x May 09 '13 at 10:45
  • The package must be the same as defined in your AndroidManifest.xml. According to yours, the full package is "com.example.gmapactivity", so it needs to be this one (and not "com.example") – Corbella May 09 '13 at 11:22
0

Okay, so I have been doing it correctly. It's just that I've been compiling it to a 3.2 android device instead of a 4.0 device, and now it works! I just don't understand the reason why 3.2 version with API level 15 won't give result when my targetSdkVersion is 17?

Compaq LE2202x
  • 2,030
  • 9
  • 45
  • 62
  • if somebody still looking answer, check here - the same problem: http://stackoverflow.com/a/17947755/1891118 – Oleksii K. Jul 30 '13 at 13:05
0

Dont get panic . simple way u can make it successful.

if you are very sure about API key in manifest file and google play service library then. follow the steps.

1) Uninstall your app from Device 2) Clean the project 3) Run the app again

This should work . and this solution worked for me ..cheers :)

Pravin Mohol
  • 665
  • 6
  • 17