What's the best approach to implement User Location Tracker in Android nowadays

102 Views Asked by At

I know and I have read some articles that give us some tutorial about how to do this, but when I want to implement one of the approach they have given, I usually got null or errors with FusedLocationProviderClient It usually happened when I turned off the GPS and turned It back on. And when I opened the Google Maps and back into my app, the FusedLocationProviderClient back to normal and gives actual longitude and latitude. Any idea or help for how can I handle this kind of bug?

2

There are 2 best solutions below

0
Raka M.A On BEST ANSWER

Nah nevermind, I solved it by replacing fusedLocation.lastLocation() with fusedLocation.currentLocation(). My bad for following tutorial that uses lastLocation

0
Jay Patel On

First do null check on FusedLocationProviderClient and then procced the steps you want to perform.