11

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.

1 Answer 1

12

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.

3
  • 1
    For Windows user: adb shell dumpsys location > dumpsys.txt to output the result to the file.
    – Andrew T.
    Commented Oct 20, 2014 at 3:45
  • 1
    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
    Commented Jul 25, 2017 at 8:31
  • Or on Windows if you're using PowerShell like you should be: adb shell dumpsys location | Out-File location.txt
    – Alan B
    Commented May 24, 2023 at 12:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .