|
|
|
|
@ -26,11 +26,11 @@ export class HMGUtils {
|
|
|
|
|
this.devicePermissionsService.requestLocationAutherization().then( async granted => {
|
|
|
|
|
if(granted == true) {
|
|
|
|
|
if (this.platform.is('android')) {
|
|
|
|
|
if ((await this.isHuaweiDevice())) {
|
|
|
|
|
this.getHMSLocation(callBack);
|
|
|
|
|
} else {
|
|
|
|
|
// if ((await this.isHuaweiDevice())) {
|
|
|
|
|
// this.getHMSLocation(callBack);
|
|
|
|
|
// } else {
|
|
|
|
|
this.getGMSLocation(callBack);
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
} else {
|
|
|
|
|
this.getIOSLocation(callBack);
|
|
|
|
|
}
|
|
|
|
|
@ -42,60 +42,60 @@ export class HMGUtils {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async isHuaweiDevice(): Promise<boolean> {
|
|
|
|
|
const result: any = await new Promise((resolve, reject) => {
|
|
|
|
|
cordova.plugins.CordovaHMSGMSCheckPlugin.isHmsAvailable(
|
|
|
|
|
"index.js",
|
|
|
|
|
(_res) => {
|
|
|
|
|
const hmsAvailable = _res === "true";
|
|
|
|
|
resolve(hmsAvailable);
|
|
|
|
|
},
|
|
|
|
|
(_err) => {
|
|
|
|
|
reject({ "status": false, "error": JSON.stringify(_err) });
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('general', 'huawei-hms-gms-error'));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
// async isHuaweiDevice(): Promise<boolean> {
|
|
|
|
|
// const result: any = await new Promise((resolve, reject) => {
|
|
|
|
|
// cordova.plugins.CordovaHMSGMSCheckPlugin.isHmsAvailable(
|
|
|
|
|
// "index.js",
|
|
|
|
|
// (_res) => {
|
|
|
|
|
// const hmsAvailable = _res === "true";
|
|
|
|
|
// resolve(hmsAvailable);
|
|
|
|
|
// },
|
|
|
|
|
// (_err) => {
|
|
|
|
|
// reject({ "status": false, "error": JSON.stringify(_err) });
|
|
|
|
|
// this.common.presentAlert(this.ts.trPK('general', 'huawei-hms-gms-error'));
|
|
|
|
|
// }
|
|
|
|
|
// );
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
private getHMSLocation(callBack: Function) {
|
|
|
|
|
try {
|
|
|
|
|
cordova.plugins.CordovaHMSLocationPlugin.requestLocation(
|
|
|
|
|
"index.js",
|
|
|
|
|
(_res) => {
|
|
|
|
|
console.log("Huawei Location Success: [Stop Getting]");
|
|
|
|
|
cordova.plugins.CordovaHMSLocationPlugin.removeLocation("", (_res) => { }, (_err) => { });
|
|
|
|
|
const location = _res.split(',')
|
|
|
|
|
console.log(location);
|
|
|
|
|
if (location.length == 3) {
|
|
|
|
|
let mock = false;
|
|
|
|
|
const lat = Number(_res.split(',')[0]);
|
|
|
|
|
const long = Number(_res.split(',')[1]);
|
|
|
|
|
const mockValue = _res.split(',')[2];
|
|
|
|
|
// private getHMSLocation(callBack: Function) {
|
|
|
|
|
// try {
|
|
|
|
|
// cordova.plugins.CordovaHMSLocationPlugin.requestLocation(
|
|
|
|
|
// "index.js",
|
|
|
|
|
// (_res) => {
|
|
|
|
|
// console.log("Huawei Location Success: [Stop Getting]");
|
|
|
|
|
// cordova.plugins.CordovaHMSLocationPlugin.removeLocation("", (_res) => { }, (_err) => { });
|
|
|
|
|
// const location = _res.split(',')
|
|
|
|
|
// console.log(location);
|
|
|
|
|
// if (location.length == 3) {
|
|
|
|
|
// let mock = false;
|
|
|
|
|
// const lat = Number(_res.split(',')[0]);
|
|
|
|
|
// const long = Number(_res.split(',')[1]);
|
|
|
|
|
// const mockValue = _res.split(',')[2];
|
|
|
|
|
|
|
|
|
|
// if (mockValue == 'true') {
|
|
|
|
|
// mock = true;
|
|
|
|
|
// } else {
|
|
|
|
|
// mock = false;
|
|
|
|
|
// }
|
|
|
|
|
callBack({"latitude":lat, "longitude":long, "isfake":mock})
|
|
|
|
|
} else {
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('general', 'invalid-huawei-location'));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(_err) => {
|
|
|
|
|
console.log("Huawei Location [Getting Error]: " + JSON.stringify(_err));
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('general', 'invalid-huawei-location'));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
// // if (mockValue == 'true') {
|
|
|
|
|
// // mock = true;
|
|
|
|
|
// // } else {
|
|
|
|
|
// // mock = false;
|
|
|
|
|
// // }
|
|
|
|
|
// callBack({"latitude":lat, "longitude":long, "isfake":mock})
|
|
|
|
|
// } else {
|
|
|
|
|
// this.common.presentAlert(this.ts.trPK('general', 'invalid-huawei-location'));
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// (_err) => {
|
|
|
|
|
// console.log("Huawei Location [Getting Error]: " + JSON.stringify(_err));
|
|
|
|
|
// this.common.presentAlert(this.ts.trPK('general', 'invalid-huawei-location'));
|
|
|
|
|
// }
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
} catch (_err) {
|
|
|
|
|
console.log("Huawei Location Plugin [Error]: " + + JSON.stringify(_err));
|
|
|
|
|
this.common.presentAlert(this.ts.trPK('general', 'huawei-plugin-issue'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// } catch (_err) {
|
|
|
|
|
// console.log("Huawei Location Plugin [Error]: " + + JSON.stringify(_err));
|
|
|
|
|
// this.common.presentAlert(this.ts.trPK('general', 'huawei-plugin-issue'));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
private getGMSLocation(callBack: Function) {
|
|
|
|
|
this.backgroundGeolocation.getCurrentLocation({ timeout: 10000, enableHighAccuracy: true, maximumAge: 3000 }).then((resp) => {
|
|
|
|
|
|