freecoding.school100% FREE · NO SIGNUP
API ArcadeISSUE #7 of 23

geolocation · getCurrentPosition · watchPosition

ApiaVSLegacy Larry
Apia saysThe Geolocation API returns the device’s coordinates after permission.

navigator.geolocation.getCurrentPosition(onSuccess, onError, options) prompts and, if allowed, returns coords.latitude/longitude/accuracy. watchPosition tracks live movement (clear with clearWatch). Requires HTTPS. Always provide the error callback — users deny, and devices fail.

Power-ups you unlock

Legacy Larry attacks — common mistakes

Boss battleRequest the position and print lat/lon, with a graceful denial message.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><button id="b">locate</button><pre id="o"></pre>
<script>document.getElementById('b').onclick=()=>{const o=document.getElementById('o');navigator.geolocation.getCurrentPosition(p=>o.textContent=p.coords.latitude.toFixed(2)+', '+p.coords.longitude.toFixed(2),e=>o.textContent='denied: '+e.message);};</script></body></html>
▶ Open the interactive comic issue
‹ Notifications · The Browser Notification ApiClipboard Api · ReadText · WriteText ›