Xamarin谷歌地图空白

4

我一直在关注:

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应用程序中使用Google地图。但我无法在我的应用程序中显示地图。它总是显示一个空白页面。我也没有看到任何错误。
我已经:
1.将必要的权限添加到我的Android清单中 2.在在线API页面上启用了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

清单中的权限(应用名称和密钥已隐藏):

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

主活动内容:
<?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" />
5个回答

9
为了在Android应用中使用谷歌地图。但我无法在我的应用程序中显示地图。它总是显示一个空白页面,也没有看到任何错误。
这可能是由以下原因导致的:
  1. 请在此处检查引用如何创建密钥库?

    一旦应用程序被签名,地图就不会起作用。
  2. 当您使用另一台计算机构建应用程序时,请从新计算机获取SHA-1。

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

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

  5. 不要忘记在Google Console中启用Google API。

这个Xamarin Android Google Map demo对您应该有所帮助。 我已尝试过这个演示项目,并使用了自己的密钥库和API_KEY,它可以正常工作。

谢谢,是演示解决了我的问题。 - gmn

3
我通过在Google Console中配置我的项目启用Android Places SDK和Maps SDK来解决了这个问题。稍等几分钟,问题就解决了!有时您可能需要重新安装应用程序到您的设备上。

2
如果您启用了Google Play应用签名,则需要使用上传apk后提供的密钥库详细信息。
发布管理 -> 应用签名(选项卡)
应用签名证书是您所需的。复制SHA-1证书指纹。

我必须这样做,还要将我的Google账户与计费账户关联。 - Jack

1

0

仅供收藏...

我遇到了同样的问题,但是在通过Google Play控制台加载我的捆绑文件应用程序之后...

我使用发布密钥库密钥签署了我的应用程序,但是...没有任何效果。从Google Play下载和安装的应用程序中没有出现地图。

因此,解决方案在这个存档主题中(在最后一篇帖子中):

https://social.msdn.microsoft.com/Forums/en-US/ef283f57-676a-498a-afa6-74ac237391f1/google-maps-blank-on-release-mode?forum=xamarinandroid

"在我的情况下,事实证明Google Play控制台使用自己的Google证书签署了发布的apk,并设置了一个与用于授权Google Maps API的SHA1不同的SHA1。"

这确实很奇怪...但无论如何...在从捆绑资源管理器下载我的应用程序并检查SHA1之后,我感到"惊讶"...只需将这个"新" SHA1添加到我的Google Cloud平台的"限制使用您的Android应用程序"部分即可。地图将出现在所有版本中。

就是这样。

如果有帮助到某人,我会很高兴。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接