我一直在关注:
并且
为了在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" />