Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not getting location updates when gps is turned off #399

Closed
kpradeepkumarreddy opened this issue Apr 27, 2020 · 5 comments
Closed

Not getting location updates when gps is turned off #399

kpradeepkumarreddy opened this issue Apr 27, 2020 · 5 comments

Comments

@kpradeepkumarreddy
Copy link

In a foreground service, i'm using FusedLocationProviderClient to request for location updates. I'm using foreground service because, i want location updates even when the app is closed. so far so good. it is working. But the problem is, if the gps is turned off then i'm not getting the onLocationResult() call back. How to handle this problem ?? Before starting the service, location was on and i got a couple of callbacks in onLocationResult() method. After sometime, user turned off the gps, after that i'm not getting the onLocationResult() call back. Any idea how to deal with this problem ??

@torryola
Copy link

There 2 possible approach I may recommend:

  1. Check or change your Location request priority settings to use
    PRIORITY_BALANCED_POWER_ACCURACY(uses any available service) instead of PRIORITY_HIGH_ACCURACY that replies mostly on GPS according to Google.
    E.g.
    LocationRequest locReq = LocationRequest.create(); locReq.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)

  2. Implement a Broadcast Receiver for changes to gps state and make a new location request using another Location Service Provider e.g. Network or Wifi if the GPS is off

@kpradeepkumarreddy
Copy link
Author

kpradeepkumarreddy commented Sep 27, 2020

There 2 possible approach I may recommend:

  1. Check or change your Location request priority settings to use
    PRIORITY_BALANCED_POWER_ACCURACY(uses any available service) instead of PRIORITY_HIGH_ACCURACY that replies mostly on GPS according to Google.
    E.g.
    LocationRequest locReq = LocationRequest.create(); locReq.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
  2. Implement a Broadcast Receiver for changes to gps state and make a new location request using another Location Service Provider e.g. Network or Wifi if the GPS is off

I already implemented both of these approaches. In the second approach, instead of starting a new location request, i'm just raising a audio notification to the user to switch on the GPS. If i make a new location request using another location service provider, will it automatically turn on the GPS or will it prompt a message to the user to TURN ON GPS ??

@torryola
Copy link

Other location providers shouldn't prompt user to turn on the GPS and it won't turn the GPS on automatically, runtime permission is required.
It depends on your requirements;

  • If it is like a tracker then notifying user to turn on the gps is best options
  • If you don't need precise use location i.e. you only need city-wide location then WiFi or Network providers should do, caveat is less accurate.
  • Other option is to call 3rd party location api if the gps is off and you still need location updates.

@kpradeepkumarreddy
Copy link
Author

Other location providers shouldn't prompt user to turn on the GPS and it won't turn the GPS on automatically, runtime permission is required.
It depends on your requirements;

  • If it is like a tracker then notifying user to turn on the gps is best options
  • If you don't need precise use location i.e. you only need city-wide location then WiFi or Network providers should do, caveat is less accurate.
  • Other option is to call 3rd party location api if the gps is off and you still need location updates.

Yes, it is a tracker. So I'm notifying the user to turn on the GPS. Can you give more details about the last option, calling 3rd party location APIs. What 3rd party location APIs are available and what have you used ?

@torryola
Copy link

There are lots of options but I have had a quick search for you to kick start your research 😉.
See below for the links.
I tried openweathermap.org api before and was alright.
Most of the 3rd-party location api uses user device's ip address to do the magic so it might not be accurate as well.
https://ipfind.com/
https://www.google.com/amp/s/rapidapi.com/blog/ip-geolocation-api/amp/

Advice:

  1. When the GPS is off, save the last user location locally, preferably use Shared Preference with a relative key e.g. Gps_LastLocation
  2. Compare the newly pulled location from any other providers aside GPS, with last saved location.
  3. If same happy days if not notify user to confirm the new location. It is a lot of work but that's what I will do as a fall back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants