MDN self-hosted library · e01.org

GeolocationPosition: toJSON() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
navigator.geolocation.getCurrentPosition((position) => {
  const json = position.toJSON();
  console.log(json); // A plain object
  console.log(typeof json); // "object"
  console.log(json.timestamp); // Same value as position.timestamp
});
js
console.log(JSON.stringify(position));