FusedLocation API - onLocationChanged is not called
Asked Answered
A

1

6

The flow in our app is the following:

  1. show a fullscreen activity explaining to the user why we need the GPS-location
  2. acquire the permission for GPS
  3. display loading spinner
  4. get first geolocation
  5. send first location to server
  6. load relevant data from server
  7. hide loading spinner

we've had multiple support requests from users saying that nothing happens and that they only see the loading spinner.

We're enforcing activated GPS-Providers at the moment, so it's not an issue of inactive locationservices.

I've managed to reproduce the bug by creating a user account on one of our phones and starting the app and I've noticed that onLocationChanged is not called

The code gets past LocationServices.FusedLocationApi.requestLocationUpdates, so it should provide locations, but it doesn't

I know that I solved this issue in the past by opening google maps, but

a) I can hardly imagine that users did not use google maps so far b) telling them to open google maps to fix an issue in our app sounds weird

here is a gist of the exact code used (I set a breakpoint on line 131, started to debug and got there, so I should be getting locations, but the method onLocationChanged is never called

Applicator answered 22/5, 2017 at 6:1 Comment(6)
what is the value of Constants.GPSINTERVAL_REGULARHazen
GPSINTERVAL_REGULAR is 2 (so 2 minutes), that shouldn't be the problem, it works on every other device I've tried so farApplicator
Hope the disconnect method is not getting called somehow before it calls the onLocationChanged due to some specific use case. Please check where you are calling locationHandler.disconnectHazen
I added a logd to both connect and disconnect and it doesn't seem to be called (atleast I can't find it in logcat). could removeLocationUpdates be executed asynchronously?Applicator
Do you mean by itself. Then it shouldn't be .Hazen
that's what I figured. God damn, probably gotta bug some google'r about it, seems to be a bug with the service itself. thanks for the help anyway!Applicator
A
2

the "solution" if you want to call it that, was to tell users to open google maps, hit the "locate me" button, wait until google maps finds them and then open our app again and report back to us whether that did anything

edit:

even better, refactor the whole thing to not use a google-api-client at all, that would look something like this:

link (it's kotlin, whatever, kotlin is nice)

edit 2: I changed it from an eventbus implementation to an rx-subject instead. eventbuses are really dirty and if possible, you should stay away from them

Applicator answered 22/5, 2017 at 11:10 Comment(3)
I was facing the same problem and your "solution" fixed it. Do you know why this happens?Roadstead
@Roadstead sadly not, my coworker speculated that it has to do something with doze mode, but we can't confirm itApplicator
@Roadstead I found out that the issue is due to the user deactivating their GPS-transponder, which clears the cache of previous gps-locations. As to why the provider doesn't retrieve new locations, I can't tellApplicator

© 2022 - 2024 — McMap. All rights reserved.