简体   繁体   中英

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

I am trying to get Current location using Fusedlocationservice.

In my gradle file i have put below playservice version

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

Now if in device have latest version of google playservice then its work well. it give proper location.

But if device have lower version then its not give current location.

Its also give warning in logcat like below:

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

So its mandatory to have latest version of playservice in device to get current location..?

If yes then i need alternet solution for this. because every user not able to update service in device so.

my code you can see here . Get Current Location 0 in marshmallow where below 23 API its give exact current Location using fused Location

Any Help will highly appreciated.

据我所知,FusedLocation是在Play Service 7.0中添加的,您发布的是6184738是6.1,我想,您可以在此处检查所有发行 变更 日志 ,因此它应该可以在具有Play Services 7.0或更高版本的设备上使用

You might want to check this document: 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 .

Note : Because it is hard to anticipate the state of each device, you must always check for a compatible Google Play services APK before you access Google Play services features.

Hope it helps!

I have put google play service version to 7.3 in gradle instead of latest version.

Because every user not have latest version of play service so if you put latest version of play service in application it always take null location if device have lower version play service. else user have to update play service to match application play service version.

So I have put lower version of playservice in app. build so its supports in each device which have equal or higher version.

got reference from doc. https://developers.google.com/android/guides/setup#ensure_devices_have_the_google_play_services_apk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM