2014-01-30 175 views
0

加載谷歌地圖的Android API V2,當我得到這個下面的錯誤無法加載地圖使用谷歌地圖的Android API V2

1. Authorization failure. 
2. Ensure that the following correspond to what is in the API Console: Package Name: com.example, API Key: AIzaSyDjm0K-ucpO5mDCPPnQ4CzVpdguqM714uo, Certificate Fingerprint: D9595FF0F329A6BBAC466C63284F83D17859894B 
3. Failed to contact Google servers. Another attempt will be made when connectivity is established. 
4. Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors). 
5. Failed to find provider info for com.google.android.gsf.gservices 

這裏是我的源代碼:

我AndroidManifest源代碼

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.example"> 
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" /> 

    <application android:label="map" android:icon="@drawable/Icon"> 
     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> 
     <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyDjm0K-ucpO5mDCPPnQ4CzVpdguqM714uo" /> 
    </application> 

    <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.google.android.providers.gsf.permission.READ_GSERVICES" /> 

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

    <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="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.READ_GSERVICES" /> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
</manifest> 

我Main.axml源代碼

Main.axml

<?xml version="1.0" encoding="utf-8"?> 
    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.MapFragment" /> 

我的活性1源代碼

Activity1.cs

using System; 

using Android.App; 
using Android.Content; 
using Android.Runtime; 
using Android.Views; 
using Android.Widget; 
using Android.OS; 

namespace map 
{ 
    [Activity(Label = "map", MainLauncher = true, Icon = "@drawable/icon")] 
    public class Activity1 : Activity 
    { 
     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 

      SetContentView(Resource.Layout.Main); 
     } 
    } 
} 

順便說一句,我使用API​​ Level 15模擬器。

這是我的API密鑰

enter image description here

+0

爲什麼標記爲C#? – Raghunandan

+0

錯誤信息在哪裏? – Jagan

+0

發佈錯誤消息以及您的佈局,我們可以幫助您解決這個問題。 – Fllo

回答

-1

我找到了答案,我的問題。我的SHA1指紋不符合我使用的證書指紋(在我的錯誤消息中)。現在我的應用程序正確加載Android谷歌地圖。

+1

您是如何驗證SHA1指紋不匹配的? – Nav

0

編寫以下功能將menifest

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

它已經在那裏......;) – Fllo

+1

好.. :) 請問你能分享你的錯誤信息... – Namy

+0

檢查您是否爲Android啓用了正確的Google地圖API服務,即Google Maps Android API v2。 – Namy

0

提高XML

<fragment 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      class="com.google.android.gms.maps.**SupportMapFragment**" /> 
+0

我的目標是API Level 15以上,SupportMapFragment在這裏不起作用。 – fulgen

+0

好吧,然後做一個新的谷歌控制檯nd試試吧。 我覺得這是你的關鍵 – Namy

+0

鏈接創建API密鑰的問題..: https://developers.google.com/maps/documentation/android/start?hl=zh-CN 你也可以從你的日食帶你到SHAI – Namy

1

雖然不推薦,它是p可以設置模擬器來支持Android Maps API v2。仿真器必須配置爲定位Google API API 17(Android 4.2.2)或更高版本的
你的是設置爲API等級15 ...

另外你需要將項目的目標API和API最小級別設置爲17(目前14)如果你想加載模擬器谷歌地圖。

在這裏閱讀的先決條件: http://docs.xamarin.com/Guides/Android/Platform_Features/Maps_and_Location/Part_2_-_Maps_API/#Configuring_Maps_API_Prerequisites

+1

要添加到此,只支持最新API的AVD。因此,使用API​​等級17或18的AVD可能具有過時的Google Play服務版本,這可能不適合您的應用程序。 –

+0

我在調試中使用真實設備,但仍無法加載地圖。它只顯示帶有Google徽標的白色屏幕並放大和縮小圖標。 – fulgen