JavaScript › Browser Storage & Web APIs

How does the Geolocation API work and what are its privacy implications?

Advanced

Answer

navigator.geolocation.getCurrentPosition() asynchronously requests the user's location, always requiring explicit browser permission first. It should only be called after a clear user action, since silent location requests are a major privacy red flag and often blocked or flagged by browsers.
navigator.geolocation.getCurrentPosition(
  pos => console.log(pos.coords.latitude, pos.coords.longitude),
  err => console.error(err.message)
);
Real-world example A delivery app asking for location only when the user taps "Use my current location."

Common follow-ups: What's the difference between getCurrentPosition() and watchPosition()?