From 3ee75abd1ac541b739f89f1e1d7f09c437a6f3f1 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 12 Nov 2020 21:26:37 +0000 Subject: [PATCH] --- ayanova/src/api/gzutil.js | 54 +++++++++++++++++++++++++++++ ayanova/src/views/cust-customer.vue | 13 +++++++ 2 files changed, 67 insertions(+) diff --git a/ayanova/src/api/gzutil.js b/ayanova/src/api/gzutil.js index 5a52d9a9..f93e35dc 100644 --- a/ayanova/src/api/gzutil.js +++ b/ayanova/src/api/gzutil.js @@ -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 } + ); + }); } /** diff --git a/ayanova/src/views/cust-customer.vue b/ayanova/src/views/cust-customer.vue index 682bc018..fdaf0b76 100644 --- a/ayanova/src/views/cust-customer.vue +++ b/ayanova/src/views/cust-customer.vue @@ -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",