finds.dev← search

// the find

domoritz/leaflet-locatecontrol

★ 874 · JavaScript · MIT · updated May 2026

A leaflet control to geolocate the user.

A Leaflet plugin that adds a locate-me button to your map, using the browser Geolocation API to show the user's position with an accuracy circle and optional compass heading. It's a narrow tool that does one thing: geolocation UI for Leaflet maps. Used in production by OpenStreetMap's homepage.

The options surface is unusually thorough — setView modes (once/always/untilPan/untilPanOrZoom), zoom range clamping, follow vs. active distinction, and per-state style overrides give you real control without forking the code. The custom event layer (locateactivate, locatelocationfound, locationtimeout) is clean and lets you build on top without monkey-patching. TypeScript definitions ship in dist, so you get autocomplete out of the box. The timeout handling is honest: after 3 consecutive timeouts it shows a visual indicator and keeps watching instead of silently dying.

The extension model (L.extend to override _drawMarker) is fragile — private methods are the extension surface, so any internal refactor is a breaking change for anyone who extended it. No React or framework wrappers are provided; framework users have to manage the Leaflet lifecycle themselves, which is always painful. The test suite (spec/) is thin — it covers basic instantiation but doesn't exercise the state machine (active → following → stopped) or error paths meaningfully. Mapbox JS support is a legacy concern at this point; Mapbox GL is what people actually use and it has its own incompatible control system.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →