9

I'm looking for a command line, or a series of commands that can dump or list the latitude and longitude on a rooted device.

I connect to a device using ADB shell. A way that will cause the coordinates to be logged to the command line is also good for me.

10

Looks like there is a way:

adb shell dumpsys location > dumpsys.txt

This will give you a file with all location service information. In this file search for 'Last Known Locations' and you should see something like:

passive: Location[network 92.915479,55.610965 acc=22 et=+1d4h10m34s255ms {Bundle[{noGPSLocation=Location[network 92.915479,55.610965 acc=22 et=+1d4h10m34s255ms {Bundle[{coarseLocation=Location[network 92.918919,55.603997 acc=2000 et=+1d4h10m34s255ms]}]}], networkLocationSource=cached, networkLocationType=wifi, travelState=stationary}]}]

network: Location[network 92.915479,55.610965 acc=22 et=+1d4h10m34s255ms {Bundle[{noGPSLocation=Location[network 92.915479,55.610965 acc=22 et=+1d4h10m34s255ms {Bundle[{coarseLocation=Location[network 92.918919,55.603997 acc=2000 et=+1d4h10m34s255ms]}]}], networkLocationSource=cached, networkLocationType=wifi, travelState=stationary}]}]

Of course, the list will include another entry if you have the GPS provider enabled on the device.

Going by android code, I tried to find out how apps get the location when they use LocationManager.getLastKnownLocation(). After a bit of following, I ended up in LocationManagerService here. which implements getLastLocation and also a dump function.

The coordinates are not stored in any file as far as I can tell. They are stored in memory in a hashmap and dumped for the dumpsys command. This also explains why a directory heirarchy search did not reveal any files with gps info.

If you want this info in a more standard format, you will need to take the app route and go with something like this. This app exports the info in a GPS or a KML file that you can feed into geo based apps.

PS: This works on non-rooted device just as well.

  • 1
    For Windows user: adb shell dumpsys location > dumpsys.txt to output the result to the file. – Andrew T. Oct 20 '14 at 3:45
  • I try to detect GPS status (active, passive) through the emulator using adb shell, the Last Known Locations info is always empty even I manually enable GPS. – talha06 Jul 25 '17 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.