Latitude And Longitude Always Come As Zero
Solution 1:
Your code — which is an awful piece of junk that keeps getting copied around — will only ever return a location if one of the getLastKnownLocation()
calls returns a location. getLastKnownLocation()
is very likely to return null
, if nothing else has been requesting locations recently.
There is no way to always get a location on demand. Your code has to be able to deal with:
A location becoming available later, such as via
onLocationChanged()
, orA location never being available, because the device is incapable of providing a location at the present time
Use getLastKnownLocation()
as an optimization, where onLocationChanged()
is your primary way of finding the location. See this sample app for an example.
Solution 2:
if you using v6.0+ Device, Open Setting > Apps > YOUR_APP_NAME > Permissions >
Allow Permission of Location.
else please turn on your location.
Post a Comment for "Latitude And Longitude Always Come As Zero"