Gets the current geolocation of a site visitor.
The getCurrentGeolocation()
method has the following limitations:
getCurrentGeolocation()
with a setTimeout()
in case the browser is set to not detect the locale. Adding the timeout lets you handle the unfulfilled promise.function getCurrentGeolocation(): Promise<CurrentGeolocation>;
import wixWindowFrontend from "wix-window-frontend";
// ...
wixWindowFrontend
.getCurrentGeolocation()
.then((obj) => {
let timestamp = obj.timestamp; // 1495027186984
let latitude = obj.coords.latitude; // 32.0971036
let longitude = obj.coords.longitude; // 34.774391099999995
let altitude = obj.coords.altitude; // null
let accuracy = obj.coords.accuracy; // 29
let altAccuracy = obj.coords.altitudeAccuracy; // null
let heading = obj.coords.heading; // null
let speed = obj.coords.speed; // null
})
.catch((error) => {
let errorMsg = error;
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.