2013-07-08 62 views
0

我无法让谷歌地图api v2在我的Android Xamarin应用程序中显示比空白屏幕更多的东西。谷歌地图Api v2 Xamarin空白屏幕

在logcat中,出现以下错误。

07-08 16:08:12.192: E/Google Maps Android API(28625): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors). 

这使我相信这是我的API密钥的问题。我不知道我在想什么。这是我的AndroidManifest.xml。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="2" android:versionName="2.0.0.0" package="com.deg.blubcnmobl.droid"> 
    <uses-sdk android:targetSdkVersion="12" /> 
    <uses-feature android:glEsVersion="0x00020000" android:required="true" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.CALL_PHONE" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <permission android:name="com.deg.blubcnmobl.droid.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> 
    <uses-permission android:name="com.deg.blubcnmobl.droid.permission.MAPS_RECEIVE" /> 
    <application android:icon="@drawable/logo" android:debuggable="true" android:enabled="true" android:persistent="false" android:allowClearUserData="true" android:theme="@android:style/Theme.Black.NoTitleBar"> 
     <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="MY_KEY" /> 
    </application> 
</manifest> 

这里是我的活动axml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<fragment 
    class="com.google.android.gms.maps.SupportMapFragment" 
    android:id="@+id/mapfragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 
</LinearLayout> 

我有谷歌地图API V2的Android API在设置中打开。

Imgur

这里是我创建的API密钥的页面。

Imgur

+0

它的一个答案,你可以张贴的AndroidManifest.xml中的全部? – Emmanuel

+0

好的,我发布了整个AndroidManifest.xml文件 –

回答

3

请务必将这些权限添加到清单

<permission 
    android:name="com.deg.blubcnmobl.droid.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature"/> 
<uses-permission android:name="com.deg.blubcnmobl.droid.permission.MAPS_RECEIVE"/> 
+0

谢谢,我错过了这个权限。但是,添加后我仍然收到相同的错误。更新问题中的AndroidManifest.xml。 –

+0

我要选择这个作为答案。我确实需要这个权限才能使其正常工作。我实际上也在使用错误的API密钥。 :( –

+0

很高兴我能够有所帮助... – Emmanuel

0

你似乎缺少您的清单多项权限。

  • 为地图样品清单V2能够在API级8上运行的和API级8上运行的向上

https://github.com/ddewaele/GoogleMapsV2WithActionBarSherlock/blob/master/GoogleMapsV2SkeletonV8/AndroidManifest.xml

  • 为地图样品布局V2能够向上

https://github.com/ddewaele/GoogleMapsV2WithActionBarSherlock/blob/master/GoogleMapsV2SkeletonV8/res/layout/activity_main.xml

  • 的地图样活性V2能够在API级别8上运行的向上

https://github.com/ddewaele/GoogleMapsV2WithActionBarSherlock/blob/master/GoogleMapsV2SkeletonV8/src/com/example/googlemaps/v2/skeleton/api8/MainActivity.java

您可以克隆以上的Git仓库,并尝试完整的GoogleMapsV2SkeletonV8应用。

+0

这是一个Xamarin项目,不是原生的。但是,我已经将您的项目用作参考,谢谢。仍然没有运气。 –

0

请查看这篇文章:Google Map Android Api V2 Sample Code not working,如果你完全确定你做了正确的步骤,仍然可以看到然后黑屏跟随第二个答案中,身份验证会被缓存到某处,尝试手动卸载应用程序(就像使用普通应用程序一样),然后再次“运行”该项目。