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 asetTimeout()
in case the browser is set to not detect the locale. Adding the timeout lets you handle the unfulfilled promise.
Syntax
function getCurrentGeolocation(): Promise<CurrentGeolocation>
getCurrentGeolocation Parameters
This function does not take any parameters.
Returns
Fulfilled - An object containing the coordinates and timestamp of the current location. Rejected - The user blocked the geolocation popup.
Return Type:
Promise<CurrentGeolocation>
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.
Was this helpful?
Get the geolocation data
Copy Code
1import wixWindow from 'wix-window';23// ...45wixWindow.getCurrentGeolocation()6 .then( (obj) => {7 let timestamp = obj.timestamp; // 14950271869848 let latitude = obj.coords.latitude; // 32.09710369 let longitude = obj.coords.longitude; // 34.77439109999999510 let altitude = obj.coords.altitude; // null11 let accuracy = obj.coords.accuracy; // 2912 let altAccuracy = obj.coords.altitudeAccuracy; // null13 let heading = obj.coords.heading; // null14 let speed = obj.coords.speed; // null15 } )16 .catch( (error) => {17 let errorMsg = error;18 });