AndroidDev
AndroidDev

Reputation: 21237

Android: Google Maps not displaying

I'm trying to get a google map to display. I can see the background (light gray background, small tiles, Google logo in the lower left), so I know that I'm close. However, there is no actual map displayed. In the LogCat, I see this message repeating over and over:

05-14 13:28:17.926: W/System.err(27458): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)

I'm using Google maps api 2 with a tethered phone for testing that is running 2.3.4.

Anyone know what might be causing this? Thanks!

package com.example.maptest;
import android.os.Bundle;
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView;

public class MyMapActivity extends MapActivity {   

  private MapView mapView;   
  private MapController mapController;

   @Override   public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.map_layout);
     mapView = (MapView)findViewById(R.id.map_view);
   }

   @Override   
   protected boolean isRouteDisplayed() {
     return false;   
   }

 }

AndroidManifest.xml

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

    <permission android:name="com.example.maptest.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.example.maptest.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-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

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

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

        <uses-library android:required="true" android:name="com.google.android.maps" />

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

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

        <activity
             android:name=".MainActivity" >
             </activity>

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

    </application>

</manifest>

Upvotes: 14

Views: 85818

Answers (14)

Slav
Slav

Reputation: 891

In my case, the API key was correct and the map was loading. However, it was not displaying on the screen.

Removing <item name="android:background"> from the app theme solved the issue. I think the background was actually drawn on top of the map.

Upvotes: 0

Ujjawal Kumar
Ujjawal Kumar

Reputation: 51

Sometimes it doesn't work on emulator, try on a physical device.

Upvotes: 0

Mafei
Mafei

Reputation: 3803

It can happen because of your key has not restricted yet. after you created your API key, you should restrict the key. https://console.cloud.google.com/apis/credentials

Upvotes: 0

SohailAziz
SohailAziz

Reputation: 8034

If you create the key using the link in google_maps_api.xml it sets the package name of the MapActivity and not the package name of the application (defined in manifest).

Make sure you have the same package name console.developers.google.com as in application manifest.

Upvotes: 0

Satyam Raikwar
Satyam Raikwar

Reputation: 45

If above all answers do not work at all .Then use another Emulator . It worked for me.

Upvotes: 0

Pranav
Pranav

Reputation: 1

May be this is because of the Google API key you have to make put google_maps_api.xml file in the values folder and paste the correct API key in it. and also you have to put this code in AndroidManifest.xml file

 <application>
 <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="YOUR_API_KEY" />

 </application>

Upvotes: 0

Samyak Upadhyay
Samyak Upadhyay

Reputation: 593

One most probable reason for this is you have not added API key in the project manifest file. Simplest way to fix this is go to the "google_maps_api.xml" file and copy the link in the file and paste it in the browser. Click on the create button in the link and copy the api key that is being generated after that and paste it in the AndroidManifest.xml in the place of "Your Api Key" which is inside the meta-data tag, compile the project this will fix the issue.

Upvotes: 0

Marius Razvan Varvarei
Marius Razvan Varvarei

Reputation: 1661

After days of struggle, I found the issue. In my manifest I had the key value stored in an xml file and it didn't work. Now i have

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzxxxxxxxxxxxxxxxxxxxxxxxkey" />    and it works.

Just removed the xml file... Hope it helps!

Upvotes: 3

Vageesha Km
Vageesha Km

Reputation: 89

go to developper console enable maps api for your device and then copy your key and paste in values->google_maps_api.xml . It works Use Android key(auto created by google service) if on android devices

Upvotes: 2

Diya Bhat
Diya Bhat

Reputation: 255

I had the same problem. The problem was in my manifest file. Check if the google maps key you have stored IN STRING.xml and google maps key in google_maps_api.xml does not have same name.

Upvotes: 0

mehmet
mehmet

Reputation: 1588

well actually I had lived this problem and it makes me crazy. after I found the solution. very simple:

1- in your project, google_maps_api.xml just check the web link is for your package name, if your package name exist and correct. go to page and get the key

To get one, follow this link, follow the directions and press "Create" at the end:

https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=...

2- just create new gooogle maps activity project get the SHA-1 code.

dont forget SHA-1 code is same in your other project but web link is uniqu for each your program

Upvotes: 1

noelyahan
noelyahan

Reputation: 4245

If you have several packages in your app beware when you create the API key you must use the package name that included in top of the android mainfest.xml file

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

Upvotes: 1

MaciejG&#243;rski
MaciejG&#243;rski

Reputation: 22232

Basically you are mixing deprecated Android API v1 with the new API v2.

The easiest way to migrate is to remove all v1 related code and start from scratch, following this link: https://developers.google.com/maps/documentation/android/start

Upvotes: 4

Rarw
Rarw

Reputation: 7663

This problem is usually related to the map API key used to sign manifest. Take a look at this post and this one which describe the same error you are experiencing. In both cases it is because the API key they used was created with the wrong keystore. You need to make sure you use your debug keystore when you create an API key in the Google API console if you are going to be testing from eclipse.

Upvotes: 17

Related Questions