Search.../

getCurrentGeolocation( )

Returns the current geolocation of the user.

Description

The getCurrentGeolocation() function returns a Promise that resolves to an object containing the current geolocation of the user.

The getCurrentGeolocation() function has the following limitations:

  • On Chrome, the function only works on HTTPS sites.
  • On Chrome, Firefox, and Safari, the function only works if the user approves a popup. If they do not approve, the promise is rejected.
  • Run getCurrentGeolocation() with a setTimeout() in case the browser is set to not detect the locale. Adding the timeout lets you handle the unfulfilled promise.

Authorization

Request

This endpoint does not take any parameters

Response Object

Fulfilled - An object containing the coordinates and timestamp of the current location. Rejected - The user blocked the geolocation popup.

NAME
TYPE
DESCRIPTION
timestamp
string

The geolocation timestamp representing the date and time at which the location was retrieved.

coords
Coordinates

An object that defines the location.

Status/Error Codes

Was this helpful?

Get the geolocation data

Copy Code
1import wixWindowFrontend from 'wix-window-frontend';
2
3// ...
4
5wixWindowFrontend.getCurrentGeolocation()
6 .then( (obj) => {
7 let timestamp = obj.timestamp; // 1495027186984
8 let latitude = obj.coords.latitude; // 32.0971036
9 let longitude = obj.coords.longitude; // 34.774391099999995
10 let altitude = obj.coords.altitude; // null
11 let accuracy = obj.coords.accuracy; // 29
12 let altAccuracy = obj.coords.altitudeAccuracy; // null
13 let heading = obj.coords.heading; // null
14 let speed = obj.coords.speed; // null
15 } )
16 .catch( (error) => {
17 let errorMsg = error;
18 });