This commit is contained in:
@@ -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 }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -889,6 +889,18 @@ async function clickHandler(menuItem) {
|
||||
params: { recordid: res.id, ayatype: window.$gz.type.Customer }
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "geocapture":
|
||||
try {
|
||||
let loc = await window.$gz.util.getGeoLocation();
|
||||
m.vm.obj.latitude = loc.latitude;
|
||||
m.vm.fieldValueChanged("latitude");
|
||||
m.vm.obj.longitude = loc.longitude;
|
||||
m.vm.fieldValueChanged("longitude");
|
||||
} catch (ex) {
|
||||
window.$gz.errorHandler.handleFormError(ex, m.vm);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
window.$gz.eventBus.$emit(
|
||||
@@ -1011,6 +1023,7 @@ async function initForm(vm) {
|
||||
//
|
||||
async function fetchTranslatedText(vm) {
|
||||
await window.$gz.translation.cacheTranslations([
|
||||
"Customer",
|
||||
"CustomerName",
|
||||
"CustomerNotes",
|
||||
"WebAddress",
|
||||
|
||||
Reference in New Issue
Block a user