bunlong/mapbox-rotate-map-based-on-mobile-web-browser-compass — explained in plain English
Analysis updated 2026-07-18 · repo last pushed 2019-10-17
Build a hiking or navigation app where the map rotates to match the phone's real-world orientation.
Create a real estate app that labels properties on a map as you point your phone at them.
Add an augmented-reality-style map experience anchored to the physical world.
Handle cross-browser compass differences between Safari, Chrome, and Firefox automatically.
| bunlong/mapbox-rotate-map-based-on-mobile-web-browser-compass | 0verflowme/alarm-clock | 0verflowme/seclists | |
|---|---|---|---|
| Language | — | CSS | — |
| Last pushed | 2019-10-17 | 2022-10-03 | 2020-05-03 |
| Maintenance | Dormant | Dormant | Dormant |
| Setup difficulty | easy | easy | easy |
| Complexity | 2/5 | 2/5 | 1/5 |
| Audience | developer | vibe coder | ops devops |
Figures from each repo's GitHub metadata at analysis time.
Only works on mobile devices with compass sensors and browsers supporting the Device Orientation API, shows an alert otherwise.
This project lets you rotate a Mapbox map based on which direction your phone is pointing. When you tilt or turn your mobile device, the map automatically rotates to match your phone's compass heading, creating an immersive, real-world navigation experience. Here's how it works: your phone's built-in compass and motion sensors constantly track which direction it's facing. The code listens to these sensor readings through your mobile browser and feeds that directional information to Mapbox, which rotates the map in real time. The rotation happens smoothly thanks to an easing function that makes the motion feel natural rather than janky. The code also handles different browser quirks, Safari reports compass data slightly differently than Chrome or Firefox, so the script detects which browser you're on and reads the compass value accordingly. This is useful for anyone building mobile-first maps or navigation apps. Imagine a hiking app where rotating your phone automatically spins the map to match your real-world orientation, or a real estate app that lets you point your phone at a property and see it labeled on the map. It's also handy for augmented reality-style experiences where the digital map should feel anchored to the physical world around you. The main constraint is that this feature only works on mobile devices with compass sensors and browsers that support the Device Orientation API. Older phones or browsers without this API will show an alert instead of silently failing. It's a nice progressive enhancement, works beautifully on modern smartphones, but degrades gracefully elsewhere.
A snippet that rotates a Mapbox map to match your phone's compass heading, using the Device Orientation API for real-time, immersive mobile navigation.
Dormant — no commits in 2+ years (last push 2019-10-17).
Setup difficulty is rated easy, with roughly 30min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Don't trust strangers blindly. Verify against the repo.