2026-01-09 23:32:39 +00:00
|
|
|
function getGeolocation(options) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// Check if geolocation is supported by the browser
|
|
|
|
|
if (!navigator.geolocation) {
|
|
|
|
|
reject(new Error("Geolocation is not supported by your browser"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-03-21 03:06:59 +00:00
|
|
|
|
2026-01-09 23:32:39 +00:00
|
|
|
// Default options if none provided
|
|
|
|
|
const geolocationOptions = options || {
|
|
|
|
|
enableHighAccuracy: true,
|
|
|
|
|
timeout: 5000,
|
2026-03-21 03:06:59 +00:00
|
|
|
maximumAge: 0,
|
2026-01-09 23:32:39 +00:00
|
|
|
};
|
2026-03-21 03:06:59 +00:00
|
|
|
|
2026-01-09 23:32:39 +00:00
|
|
|
// Call the geolocation API
|
|
|
|
|
navigator.geolocation.getCurrentPosition(
|
2026-03-21 03:06:59 +00:00
|
|
|
(position) => resolve(position),
|
|
|
|
|
(error) => reject(error),
|
|
|
|
|
geolocationOptions,
|
2026-01-09 23:32:39 +00:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|