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.
Answer
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.
No comments:
Post a Comment