我已将现有的Android应用迁移到Android Studio / Gradle。我现在遇到了以前正在使用的地图问题。
我从Google克隆了android-maps-utils库并将其添加到我的项目中。我已将android-map-utils的依赖项添加到我的gradle.build文件中。
当我加载包含Map的屏幕时,我从LogCat获得以下序列:
I / Google Maps Android API:Google Play服务客户端版本: 5089000
I / Google Maps Android API:Google Play服务包版本:5089036
I / Google Maps Android API:无法与Google联系 服务器。连接时将进行另一次尝试 成立。
E / Google Maps Android API:无法加载地图。错误 联系Google服务器。这可能是一个身份验证问题 (但可能是由于网络错误)。
我将获得一个新的Maps API密钥,但我很好奇是否有人认为Google Play服务客户端版本/软件包版本差异可能导致问题,然后我如何解决它?
答案 0 :(得分:2)
显示的软件包版本比客户端版本新,因此在您的情况下,它不是版本兼容性问题。
鉴于您已拥有API密钥,您案例中最可能的原因是:
或
或
<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"/> <!-- The following two permissions are not required to use Google Maps Android API v2, but are recommended. They are required if you access the user's current location, either programmatically, or by enabling the My Location layer.--> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
请参阅Maps API的入门部分中的应用签名/注册说明: https://developers.google.com/maps/documentation/android/start#get_an_android_certificate_and_the_google_maps_api_key
此外,您可以在加载地图之前尝试添加以下代码,以获取有关访问失败的更多详细信息:
String googleError = null;
switch (MapsInitializer.initialize(ctx)) { // or GooglePlayServicesUtil.isGooglePlayServicesAvailable(ctx)
case ConnectionResult.SERVICE_MISSING: googleError = "Failed to connect to google mapping service: Service Missing"; break;
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: googleError = "Failed to connect to google mapping service: Google Play services out of date. Service Version Update Required"; break;
case ConnectionResult.SERVICE_DISABLED: googleError = "Failed to connect to google mapping service: Service Disabled. Possibly app is missing API key or is not a signed app permitted to use API key."; break;
case ConnectionResult.SERVICE_INVALID: googleError = "Failed to connect to google mapping service: Service Invalid. Possibly app is missing API key or is not a signed app permitted to use API key."; break;
case ConnectionResult.DATE_INVALID: googleError = "Failed to connect to google mapping service: Date Invalid"; break;
}
if (googleError != null)
Log.d("MyApp", googleError);