A Cloudflare Worker that tracks your location, resolves it to points of interest (POIs) using OpenStreetMap, or maps it to defined "hidden zones" (like Home or Work) and serve it via an api.
-
Install Dependencies
bun install
-
Configure Wrangler Ensure you have a
wrangler.tomlfile configured with your Cloudflare account details. You will need:- A KV Namespace bound as
LOC_KV. - A
HIDDEN_ZONESvariable (can be set via.dev.varsfor local development or secrets for production). USERandPASSvariables for updating location
- A KV Namespace bound as
-
Environment Variables
HIDDEN_ZONES: A JSON string defining your private zones.[ { "name": "Home", "lat": 18.300615, "lon": -64.825609, "radius": 0.5 }, { "name": "Office", "lat": 44.380642140432165, "lon": -73.22706310693646, "radius": 0.2 } ]]USER: Username (HTTP basic auth)PASS: Password (HTTP basic auth)
Start the local development server:
bun run devDeploy to Cloudflare Workers:
bun run deploySend a JSON payload to the worker root:
POST /
Content-Type: application/json
Headers: Authorization: U3RhclRoaXNSZXBvUHdlYXNlOlN1cGVyU2VjcmV0UGFzc3dvcmQ=
{
"lat": 48.8579,
"lon": 2.2948,
"batt": 85,
"bs": 1
}}You can use an app OwnTracks (Android / iOS) to periodically send your location to the api
Retrieve the last known location and battery level:
GET /Response:
{
"location": "Eiffel Tower (Paris, France)",
"battery": 85,
"batteryStatus": 1
}}