Android: Google Maps not displaying

2019-01-19 00:14发布

问题:

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>

回答1:

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.



回答2:

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



回答3:

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


回答4:

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



回答5:

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



回答6:

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!



回答7:

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.



回答8:

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.