Jul 2024Web1 min read

Real-time Location Tracker

Browser GPS sharing over Socket.IO: every connected client broadcasts coordinates; a shared Leaflet map shows live markers with device popups and auto-fit bounds.

Socket.IO + Leaflet: live GPS markers that appear, move, and vanish on disconnect

Node.js / Socket.IO / Leaflet.js

What it does

Open the page on two phones. Allow location. Both markers show up on one map, move as you walk, and disappear when a tab closes. The server is a thin relay: no database, no sessions beyond socket.id, and no auth: anyone with the page URL sees every connected client’s live location. Fine for a demo on a private link; a real deploy needs access control first.

Architecture

socket.on('sendLocation', (coords) => {
  io.emit('receiveLocation', { id: socket.id, deviceInfo, ...coords });
});

socket.on('disconnect', () => {
  io.emit('userDisconnect', socket.id);
});

Clients own markers keyed by socket.id. Disconnect removes the marker everywhere. fitBounds keeps everyone visible until the user pans manually.

What it demonstrates

  • WebSocket broadcast as a message bus
  • Browser Geolocation + Leaflet without a mapping SaaS
  • Keeping server state near zero when the client can hold the UI model