With the more recent version of Android... you are supposed to check if the user has given you permission before you use their location info. I\'ve gone through the android
I was facing the same error as you. To save battery, i wanted to use the lastKnownLocation instead of polling all the time. Sometimes, lastKnownLocation was null, no matter what i checked before.
If you have a look in the documentation, it is said that:
The getLastLocation() method returns a Location object from which you can retrieve the latitude and longitude coordinates of a geographic location. The location object returned may be null in rare cases when the location is not available.
To fix this, i implemented a combination of using the lastKnownLocation, and polling for a new position as a fallback.
My basic structure here is
This approach works like a charm. I have'nt managed to figure out a better solution so far, but i would suggest you to try it out.