当 google 播放服务在应用程序和设备中不同时,使用融合位置获取 CurrentLocation 0

Getting CurrentLocation 0 using fused location when google play service is different in app and device

我正在尝试使用 Fusedlocationservice 获取当前位置。

在我的 gradle 文件中,我将播放服务版本放在下面

compile 'com.google.android.gms:play-services:9.4.0'

现在,如果设备中有最新版本的 google 播放服务,那么它可以正常工作。它给出了正确的位置。

但如果设备版本较低,则不会提供当前位置。

它也在 logcat 中发出警告,如下所示:

W/GooglePlayServicesUtil: Google Play services out of date.  Requires 9452000 but found 6184738

所以必须在设备中安装最新版本的 playservice 才能获取当前位置..?

如果是,那么我需要 alternet 解决方案。因为每个用户都无法更新设备中的服务。

我的代码你可以在这里看到。Get Current Location 0 in marshmallow where below 23 API its give exact current Location using fused Location

任何帮助将不胜感激。

据我所知,FusedLocation 是在 Play Service 7.0 中添加的,您发布的是 6184738 我猜是 6.1,您可以查看 here all the release changelog,所以它应在具有播放服务 7.0 或更高版本的设备上运行

您可能需要查看此文档:Ensure Devices Have the Google Play services APK

As described in the Google Play services overview, Google Play delivers service updates for users on Android 2.3 and higher through the Google Play Store app. However, updates might not reach all users immediately, so your app should verify the version available before attempting to perform API transactio

You are strongly encouraged to use the GoogleApiClient class to access Google Play services features. This approach allows you to attach an OnConnectionFailedListener object to your client. To detect if the device has the appropriate version of the Google Play services APK, implement the onConnectionFailed() callback method. If the connection fails due to a missing or out-of-date version of the Google Play APK, the callback receives an error code such as SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED. To learn more about how to build your client and handle such connection errors, see Accessing Google APIs.

Another approach is to use the isGooglePlayServicesAvailable() method. You might call this method in the onResume() method of the main activity. If the result code is SUCCESS, then the Google Play services APK is up-to-date and you can continue to make a connection. If, however, the result code is SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, or SERVICE_DISABLED, then the user needs to install an update. In this case, call the getErrorDialog() method and pass it the result error code. The method returns a Dialog you should show, which provides an appropriate message about the error and provides an action that takes the user to Google Play Store to install the update.

注意:因为很难预测每台设备的状态,所以在访问[=34之前,您必须始终检查兼容的Google Play服务APK =] 播放服务功能。

希望对您有所帮助!

我已将 google play service 版本改为 gradle 中的 7.3 而不是最新版本。

因为每个用户都没有最新版本的播放服务,所以如果您将最新版本的播放服务放在应用程序中,如果设备有较低版本的播放服务,它总是会占用空位置。否则用户必须更新播放服务以匹配应用程序播放服务版本。

所以我在app里放了低版本的playservice。构建使其支持具有相同或更高版本的每个设备。

从文档中获得参考。 https://developers.google.com/android/guides/setup#ensure_devices_have_the_google_play_services_apk