fixed location issue for ios and separated code for

mohemm-nfc-enad
umasoodch 5 years ago
parent 6f92708417
commit e1a2a9840f

@ -59,8 +59,8 @@ export class AttendScanService {
this.permissions.requestLocationAutherization().then(granted => { this.permissions.requestLocationAutherization().then(granted => {
this.location = granted as boolean; this.location = granted as boolean;
if (this.location) { if (this.location) {
this.backgroundGeolocation.getCurrentLocation({ timeout: 10000, enableHighAccuracy: true, maximumAge: 3000 }).then((resp) => { if (this.platform.is('android')) {
if (this.platform.is('android')) { this.backgroundGeolocation.getCurrentLocation({ timeout: 10000, enableHighAccuracy: true, maximumAge: 3000 }).then((resp) => {
if (resp && (resp.latitude && resp.longitude)) { if (resp && (resp.latitude && resp.longitude)) {
if (resp.isFromMockProvider || resp.mockLocationsEnabled) { if (resp.isFromMockProvider || resp.mockLocationsEnabled) {
this.isFakeLocationUsed = true; this.isFakeLocationUsed = true;
@ -68,19 +68,25 @@ export class AttendScanService {
this.lat = resp.latitude; this.lat = resp.latitude;
this.longt = resp.longitude; this.longt = resp.longitude;
this.attendance(); this.attendance();
} else {
this.common.presentAlert(this.ts.trPK('home', 'position-error'));
} }
} else { }, (error) => {
if (resp && (resp.latitude && resp.longitude)) { this.common.presentAlert(this.ts.trPK('home', 'position-error'));
this.lat = resp.latitude; });
this.longt = resp.longitude; } else {
this.geolocation.getCurrentPosition({maximumAge: 3000, timeout: 10000, enableHighAccuracy: true}).then(resp => {
if(resp && resp.coords.latitude && resp.coords.longitude) {
this.lat = resp.coords.latitude;
this.longt = resp.coords.longitude;
this.attendance(); this.attendance();
} else { } else {
this.common.presentAlert(this.ts.trPK('home', 'position-error')); this.common.presentAlert(this.ts.trPK('home', 'position-error'));
} }
} }).catch(error => {
}, (error) => {
this.common.presentAlert(this.ts.trPK('home', 'position-error')); this.common.presentAlert(this.ts.trPK('home', 'position-error'));
}); });
}
} else { } else {
return false; return false;
} }

@ -246,8 +246,8 @@ export class HomePage implements OnInit {
this.permissions.requestLocationAutherization().then(granted => { this.permissions.requestLocationAutherization().then(granted => {
this.location = granted as boolean; this.location = granted as boolean;
if (this.location) { if (this.location) {
this.backgroundGeolocation.getCurrentLocation({ timeout: 10000, enableHighAccuracy: true, maximumAge: 3000 }).then((resp) => { if (this.platform.is('android')) {
if (this.platform.is('android')) { this.backgroundGeolocation.getCurrentLocation({ timeout: 10000, enableHighAccuracy: true, maximumAge: 3000 }).then((resp) => {
if (resp && (resp.latitude && resp.longitude)) { if (resp && (resp.latitude && resp.longitude)) {
if (resp.isFromMockProvider || resp.mockLocationsEnabled) { if (resp.isFromMockProvider || resp.mockLocationsEnabled) {
this.isFakeLocationUsed = true; this.isFakeLocationUsed = true;
@ -255,19 +255,25 @@ export class HomePage implements OnInit {
this.lat = resp.latitude; this.lat = resp.latitude;
this.longt = resp.longitude; this.longt = resp.longitude;
this.attendance(); this.attendance();
} else {
this.common.presentAlert(this.ts.trPK('home', 'position-error'));
} }
} else { }, (error) => {
if (resp && (resp.latitude && resp.longitude)) { this.common.presentAlert(this.ts.trPK('home', 'position-error'));
this.lat = resp.latitude; });
this.longt = resp.longitude; } else {
this.geolocation.getCurrentPosition({maximumAge: 3000, timeout: 10000, enableHighAccuracy: true}).then(resp => {
if(resp && resp.coords.latitude && resp.coords.longitude) {
this.lat = resp.coords.latitude;
this.longt = resp.coords.longitude;
this.attendance(); this.attendance();
} else { } else {
this.common.presentAlert(this.ts.trPK('home', 'position-error')); this.common.presentAlert(this.ts.trPK('home', 'position-error'));
} }
} }).catch(error => {
}, (error) => {
this.common.presentAlert(this.ts.trPK('home', 'position-error')); this.common.presentAlert(this.ts.trPK('home', 'position-error'));
}); });
}
} else { } else {
return false; return false;
} }

Loading…
Cancel
Save