In this example, calling position.coords.toJSON()
returns a JSON representation of the GeolocationCoordinates
object.
navigator.geolocation.getCurrentPosition((position) => {
console.log(position.coords.toJSON());
});
This would log a JSON object like so:
{
"accuracy": 12.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.coords)
directly; it will call toJSON()
automatically.
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