无法加载谷歌地图v2的Android

时间:2015-01-03 20:16:04

标签: android maps

当我使用debug.keystore时,谷歌地图显示得很好。没问题。但我使用应用程序密钥库生成的api密钥,我收到以下消息。

01-03 22:02:00.670: E/Google Maps Android API(11159): Authorization failure.  Please 
see https://developers.google.com/maps/documentation/android/start for how to  
correctly set up the map.

01-03 22:02:00.680: E/Google Maps Android API(11159): In the Google Developer     
Console  
(https://console.developers.google.com)

01-03 22:02:00.680: E/Google Maps Android API(11159): Ensure that the "Google Maps   
Android API v2" is enabled.

01-03 22:02:00.680: E/Google Maps Android API(11159): Ensure that the following 
Android Key exists:

01-03 22:02:00.680: E/Google Maps Android API(11159):   API Key: 
AIzaSyABd0LjyKN0ULwiotTfoGTxsKy4sfPuzoc

01-03 22:02:00.680: E/Google Maps Android API(11159):   Android Application   
(<cert_fingerprint>;<package_name>): 
release_api_key;com.example.hellomap

01-03 22:02:00.690: I/Google Maps Android API(11159): Failed to contact Google  
servers. Another attempt will be made when connectivity is established.

这是我的代码

 <?xml version="1.0" encoding="utf-8"?>
  <!-- TODO: Replace "com.example.hellomap" with your desired package name -->
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.hellomap"
      android:versionCode="1"
      android:versionName="1.0">

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

    <!-- TODO: Replace "com.example.hellomap" with your package name -->
     <permission
        android:name="com.example.hellomap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
     <uses-permission android:name="com.example.hellomap.permission.MAPS_RECEIVE"/>

   <!-- The following four permissions -->
   <uses-permission android:name="android.permission.INTERNET"/>
   <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"/>

<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
<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"/>

<application
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher">

    <!-- TODO: Insert your Maps API key here. See this page for more information:
         https://developers.google.com/maps/documentation/android
   /start#the_google_maps_api_key -->
    <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="my key"/>
      <meta-data 
                android:name="com.google.android.gms.version" 
                android:value="@integer/google_play_services_version" />
    <activity
            android:name="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>
  </application>

MainActivity包含以下内容......

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MainActivity extends FragmentActivity {
private GoogleMap mMap;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    setUpMapIfNeeded();
}

@Override
protected void onResume() {
    super.onResume();
    setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
    if (mMap != null) {
        return;
    }
    mMap = ((SupportMapFragment)   
       getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    if (mMap == null) {
        return;
    }

    }
}

换句话说,谷歌无法识别已发布的密钥,而debug.keystore密钥可以正常工作。我错过了什么吗?之前我曾使用谷歌地图,但从未遇到过这个问题。谷歌api控制台中的Google Maps Android API v2已开启。

谢谢。

1 个答案:

答案 0 :(得分:0)

密钥的密钥或包名称不匹配。