Phone Location Logger


Reading time: about 2 minutes

If you are using Google Play Services on your Android phone, Google receives and keeps track of your location history. This includes your GPS coordinates and timestamps. Because of the privacy implications, I have revoked pretty much all permissions from Google Play Services and disabled my Location History on my Google settings (as if they would respect that).

But while it might be creepy if a random company has this data, it would be useful if I still have it. After all, who doesn’t want to know the location of a park that they stumbled upon randomly on a vacation 3 years ago.

I remember seeing some location trackers while browsing through F-Droid. I found various applications there, and picked one that was recently updated. The app was a Nextcloud companion app, with support for custom servers. Since I didn’t want a heavy Nextcloud install just to keep track of my location, I decided to go with the custom server approach.

In the end, I decided that the easiest path is to make a small CGI script in Python that appends JSON encoded lines to a text file. Because of this accessible data format, I can process this file in pretty much every programming language, import it to whatever database I want and query it in whatever way I see fit.

The app I went with is called PhoneTrack. You can find the APK and source code links on F-Droid. It replaces the parameters in the URL, logging every parameter looks like this: https://example.com/cgi-bin/locationrecorder.py ?acc=%ACC&alt=%ALT&batt=%BATT&dir=%DIR&lat=%LAT&lon=%LON&sat=%SAT&spd=%SPD &timestamp=%TIMESTAMP

Here’s the script in all it’s glory.

import cgi
import json

PATH = '/home/databases/location.txt'

print('Content-Type: text/plain\n')
form = cgi.FieldStorage()

# Check authentication token
if form.getvalue('token') != 'SECRET_VALUE':
    raise Exception('Nope')

obj = {
    'accuracy':   form.getvalue('acc'),
    'altitude':   form.getvalue('alt'),
    'battery':    form.getvalue('batt'),
    'bearing':    form.getvalue('dir'),
    'latitude':   form.getvalue('lat'),
    'longitude':  form.getvalue('lon'),
    'satellites': form.getvalue('sat'),
    'speed':      form.getvalue('spd'),
    'timestamp':  form.getvalue('timestamp'),
}

with open(PATH, 'a+') as log:
    line = json.dumps(obj)
    log.write(f'{line}\n')

The following pages link here

Citation

If you find this work useful, please cite it as:
@article{yaltirakli201903phonelocationlogger,
  title   = "Phone Location Logger",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2019",
  url     = "https://www.gkbrk.com/2019/03/phone-location-logger/"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "Phone Location Logger", March, 2019. [Online]. Available: https://www.gkbrk.com/2019/03/phone-location-logger/. [Accessed Nov. 12, 2024].
APA Style
Yaltirakli, G. (2019, March 23). Phone Location Logger. https://www.gkbrk.com/2019/03/phone-location-logger/
Bluebook Style
Gokberk Yaltirakli, Phone Location Logger, GKBRK.COM (Mar. 23, 2019), https://www.gkbrk.com/2019/03/phone-location-logger/

Comments

Comment by Simao
2019-04-04 at 08:47
Spam probability: 0.155%

I don't know exactly how phonetrack gets the location, but if it uses the android apis doesn't it still use google services to get the location? Meaning google can still store your location.

Comment by admin
2019-03-25 at 11:07
Spam probability: 0.092%

@Philipp Opening the file in 'a+' mode creates the file if it doesn't exist, and appends if it does exist.

Comment by Philipp Hagemeister
2019-03-24 at 17:52
Spam probability: 0.177%

Why are you opening the file in 'a+' mode? Shouldn't it be just 'a'?

© 2024 Gokberk Yaltirakli