Xamarin谷歌地图空白

gmn*_*gmn 2 c# android google-maps xamarin

我一直在关注:

https://developer.xamarin.com/guides/android/platform_features/maps_and_location/maps/obtaining_a_google_maps_api_key/

https://developer.xamarin.com/guides/android/platform_features/maps_and_location/maps/obtaining_a_google_maps_api_key/

为了在Android应用中使用谷歌地图.我根本无法在我的应用程序中显示地图.它始终显示空白页面.我也没有看到任何错误.

我有:

  1. 为我的Android清单添加了必要的权限
  2. 在线启用apis页面中的API.
  3. 基于使用本地调试密钥库添加凭据
  4. 在我的主活动页面上将地图添加为地图片段.

在线的所有内容都指向调试密钥不正确,但我必须尝试使用​​此功能,但仍然无法正常工作.可能会以某种方式选择另一个吗?

此外,我不确定其重要性,但是当我尝试访问时,mapfragment在恢复时总是为空.

密钥库命令:

keytool -list -v -keystore "C:\Users\<My User folder>\AppData\Local\Xamarin\Mono for Android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
Run Code Online (Sandbox Code Playgroud)

清单中的权限(使用AppName和密钥隐藏):

  <!-- Google Maps for Android v2 requires OpenGL ES v2 -->
    <uses-feature android:glEsVersion="0x00020000" android:required="true" />
    <!-- We need to be able to download map tiles and access Google Play Services-->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Allow the application to access Google web-based services. -->
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <!-- Google Maps for Android v2 will cache map tiles on external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- Permission to receive remote notifications from Google Play Services -->
    <!-- Notice here that we have the package name of our application as a prefix on the permissions. -->
    <permission android:name="APPNAME.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
    <uses-permission android:name="APPNAME.permission.MAPS_RECEIVE" />
    <!-- These are optional, but recommended. They will allow Maps to use the My Location provider. -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application android:label="<app name>">
        <!-- Put your Google Maps V2 API Key here. -->
        <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="MYKEY" />
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    </application>
Run Code Online (Sandbox Code Playgroud)

主要活动内容:

<?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" />
Run Code Online (Sandbox Code Playgroud)

Mik*_* Ma 5

为了在Android应用中使用谷歌地图.我根本无法在我的应用程序中显示地图.它始终显示空白页面.我也没有看到任何错误.

这可能是由以下原因引起的:

  1. 检查此处的参考如何创建密钥库? 应用程序签名后,地图将无法正常工作.

  2. 当您使用其他计算机构建应用程序时,请从新计算机上获取SHA-1.

  3. 不要使用Java生成的密钥库.请使用Visual Studio生成的密钥库.它在C:\Users\username\AppData\Local\Xamarin\Mono for Android/.

  4. 使用包含Google API的模拟器.

  5. 不要忘记在Google控制台中启用Google API.

这个Xamarin Android谷歌地图演示应该对你有所帮助.我用我自己的密钥库和API_KEY尝试了这个演示,它可以工作.