JavaScript Navigator geolocation Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

navigator.geolocation is a read-only property that returns a Geolocation object (MDN). It is the entry point to the Geolocation API for one-shot or live location reads.

Read the notes below before you rely on this property. Prefer feature detection when support is limited.

Syntax

Use navigator.geolocation. Start with this line.

JavaScript
navigator.geolocation
CallWhat it does
navigator.geolocationPrimary signature.

Built into the browser. Read navigator.geolocation on Navigator — no import required.

Library declarations
JavaScript
navigator.geolocation

Parameters

ParameterDescription
Success callbackRequired. Receives GeolocationPosition
OptionsOptional. enableHighAccuracy, timeout, maximumAge

Return Value

Return ValueDescription
*Geolocation object

JavaScript Examples

Example 1 — Feature-Detect

Check whether the Geolocation API is available before calling it.

JavaScript
const supported = "geolocation" in navigator;
console.log(supported ? "geolocation available" : "geolocation missing");
Try It Yourself

How It Works

  1. Use in. "geolocation" in navigator checks for the property.
  2. Expect Baseline support. Modern browsers usually have it on HTTPS.
  3. Still need permission. Presence ≠ permission granted.
  4. Branch early. Show a fallback UI when missing.

Example 2 — getCurrentPosition

Request one location reading after a button click (triggers the permission prompt).

JavaScript
function onSuccess(position) {
  const { latitude, longitude } = position.coords;
  console.log(latitude + ", " + longitude);
}

function onError(err) {
  console.log(err.code + ": " + err.message);
}

if (!navigator.geolocation) {
  console.log("unsupported");
} else {
  navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
Try It Yourself

How It Works

  1. Detect the API. Exit if navigator.geolocation is missing.
  2. Pass success + error. Success gets a GeolocationPosition.
  3. Read coords. Use latitude and longitude.
  4. Handle denial. Error callback covers permission and timeouts.

Example 3 — watchPosition + clearWatch

Listen for movement updates, then stop with the returned watch ID.

JavaScript
if (!navigator.geolocation) {
  console.log("unsupported");
} else {
  const id = navigator.geolocation.watchPosition(
    (pos) => console.log(pos.coords.latitude),
    (err) => console.log(err.message)
  );
  // later:
  // navigator.geolocation.clearWatch(id);
  console.log("watch id: " + id);
}
Try It Yourself

How It Works

  1. Start a watch. watchPosition registers ongoing updates.
  2. Save the ID. The return value identifies this watch.
  3. Log on move. Success runs again when position changes.
  4. Clear when done. Call clearWatch(id) to stop battery drain.

Browser Support

Navigator.geolocation is Baseline Widely available on MDN (since about July 2015). It requires a secure context and explicit user permission. It is not Deprecated, Experimental, or Non-standard.

✓ Baseline · Widely available

Navigator.geolocation

Supported across modern desktop and mobile browsers on HTTPS. Always feature-detect and handle permission denial.

95% Modern browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
navigator.geolocation Excellent

Bottom line: Use HTTPS, request location after a clear user action, handle errors, and clear watch IDs when finished.

Frequently Asked Questions

It is a read-only Navigator property that returns a Geolocation object — the entry point to the Geolocation API for reading the device’s location (with user permission).
No. MDN marks it Baseline Widely available (since about July 2015). It is not Deprecated, Experimental, or Non-standard. It does require a secure context (HTTPS / localhost).
Yes. When your page requests location, the browser asks for permission. Policies and UI differ by browser. Always handle denial gracefully.
Call navigator.geolocation.getCurrentPosition(success, error, options). The success callback receives a GeolocationPosition with coords.latitude and coords.longitude.
watchPosition(success, error, options) keeps updating as the device moves and returns a watch ID. Stop updates with clearWatch(id).
No. The property is read-only. You call methods on the returned Geolocation object.

Next: globalPrivacyControl

Learn the modern Global Privacy Control preference signal.

globalPrivacyControl →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful