Skip to content Skip to sidebar Skip to footer

Latitude And Longitude Always Come As Zero

The Below Code always Returns Zero....as Latitude and Longitude... I am Using a GPSTrack Class To Get the current location of and then Show that Location into the Maps..but GPS Tra

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(), or

  • A 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"