Skip to content

Instantly share code, notes, and snippets.

@contolini
Last active June 1, 2024 00:51
Show Gist options
  • Save contolini/e0e3df8a595ea171cf9d20cc94a162ab to your computer and use it in GitHub Desktop.
Save contolini/e0e3df8a595ea171cf9d20cc94a162ab to your computer and use it in GitHub Desktop.
How to create a simple real-time location tracking website a la https://whereis.contolini.com

The steps below require a smartphone running Android. If you're an iPhone user you'll have to find an appropriate iOS app for step #4. Maybe this?

  1. Copy this HTML file to wherever you want your page to live.
  2. Create an account at MapBox and generate an API token on your account page.
  3. Replace my API token with yours in the HTML file.
  4. Install GPS Logger for Android on your phone.
  5. Create an account at ThingSpeak and get an API key. We'll use ThingSpeak to store your GPS coordinates.
  6. Create a new ThingSpeak channel. Enable all eight fields and make the channel public. It should look like this.
  7. Replace my channel ID with yours in the HTML file. Your channel ID can be found at the top of your channel's settings page.
  8. Open GPS Logger for Android and tap the menu and go to the "Logging details" screen.
  9. Enable "Log to custom URL" and add https://api.thingspeak.com/update?api_key=YOUR_THINGSPEAK_API_KEY&field1=%TIME&field2=%LAT&field3=%LON&field4=%SAT&field5=%ALT&field6=%SPD&field7=%DIR&field8=%BATT as the URL (replacing YOUR_THINGSPEAK_API_KEY with your ThingSpeak API key). We'll actually only use the LAT and LON fields (field2 and field3) but you might as well log the other stuff because hey why not.
  10. Explore GPS Logger for Android's other configuration options. For example, under "Performance", I set the logging interval to 300 seconds so that it'll push my location to ThingSpeak every five minutes. I also set a distance filter of 30 meters so that it won't log my location if I'm still in the same spot I was five minutes ago.
  11. Tap the "Start Logging" button from the app's home screen and wait a few seconds for it to log your position.
  12. Cross your fingers and open your HTML file in a browser!

Leave the app running on your phone in the background whenever you want tracking enabled. Oh, and you'll probably want to replace the location marker image. 😄

@midir99
Copy link

midir99 commented Apr 29, 2024

Thank you, I'll try this. Very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment