This question already has an answer here:
For my new app, I need to get user location using GPS. To do so, I am using fusedLocationProviderApi.getLastLocation
. Most of the time I am getting null
.
But then I realized that all the APIs are intended to get notified on Location changed. But I want to take current exact location of user (consider user not moving) in the app.
How do I get the Location object so that I don't get null
each time.
You can use this code in
OnCreate()
method to get location