This commit is contained in:
2020-11-12 21:26:37 +00:00
parent 1460ca5903
commit 3ee75abd1a
2 changed files with 67 additions and 0 deletions

View File

@@ -486,6 +486,60 @@ export default {
//
isBoolean: function(obj) {
return obj === true || obj === false || typeof variable === "boolean";
},
///////////////////////////////////////////////
// Use geolocation api to attempt to get current location
// try high accuracy first and downgrade if unavailable
//
// function getCurrentLocation(options) {
// return new Promise((resolve, reject) => {
// navigator.geolocation.getCurrentPosition(resolve, ({code, message}) =>
// reject(Object.assign(new Error(message), {name: "PositionError", code})),
// options);
// });
// };
getGeoLocation: async function() {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
function successHigh(pos) {
resolve({
latitude: pos.coords.latitude,
longitude: pos.coords.longitude
});
},
function error(err) {
//if here due to timeout getting high accuracy then try again with low accuracy
if (error.code == error.TIMEOUT) {
navigator.geolocation.getCurrentPosition(
function successLow(pos) {
resolve({
latitude: pos.coords.latitude,
longitude: pos.coords.longitude
});
},
function error(err) {
reject(
new Error(
`ERROR getting location(low_accuracy: ${err.code}): ${err.message}`
)
);
},
{ maximumAge: 600000, timeout: 10000, enableHighAccuracy: false }
);
return;
}
reject(
new Error(
`ERROR GETTING LOCATION(high_accuracy:${err.code}): ${err.message}`
)
);
},
{ maximumAge: 600000, timeout: 5000, enableHighAccuracy: true }
);
});
}
/**