A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPosition/toJSON below:

GeolocationPosition: toJSON() method - Web APIs

GeolocationPosition: toJSON() method

Baseline 2024

Newly available

The toJSON() method of the GeolocationPosition interface is a serializer; it returns a JSON representation of the GeolocationPosition object.

Syntax Parameters

None.

Return value

A JSON object that is the serialization of the GeolocationPosition object.

Examples Using the toJSON() method

In this example, calling position.toJSON() returns a JSON representation of the GeolocationPosition object.

navigator.geolocation.getCurrentPosition((position) => {
  console.log(position.toJSON());
});

This would log a JSON object like so:

{
  "timestamp": 1717509611840,
  "coords": {
    "accuracy": 13.0,
    "latitude": 53.0,
    "longitude": 8.0,
    "altitude": null,
    "altitudeAccuracy": null,
    "heading": null,
    "speed": null
  }
}

To get a JSON string, you can use JSON.stringify(position) directly; it will call toJSON() automatically.

Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4