diff --git a/src/core/services/geolocation.ts b/src/core/services/geolocation.ts index e736cdba8..dbbd977c0 100644 --- a/src/core/services/geolocation.ts +++ b/src/core/services/geolocation.ts @@ -22,10 +22,17 @@ import { CoreUtils } from './utils/utils'; import { CorePlatform } from './platform'; import { CoreSilentError } from '@classes/errors/silenterror'; import { CoreSubscriptions } from '@singletons/subscriptions'; +import { CoreLogger } from '@singletons/logger'; @Injectable({ providedIn: 'root' }) export class CoreGeolocationProvider { + protected logger: CoreLogger; + + constructor() { + this.logger = CoreLogger.getInstance('CoreGeolocationProvider'); + } + /** * Get current user coordinates. * @@ -34,16 +41,21 @@ export class CoreGeolocationProvider { */ async getCoordinates(): Promise { try { + this.logger.log('Getting coordinates.'); await this.authorizeLocation(); await this.enableLocation(); + this.logger.log('Getting coordinates: authorized and enabled.'); const result = await Geolocation.getCurrentPosition({ enableHighAccuracy: true, timeout: 30000, }); + this.logger.log('Coordinates retrieved'); return result.coords; } catch (error) { + this.logger.log('Error getting coordinates.', error); + if (this.isCordovaPermissionDeniedError(error)) { throw new CoreGeolocationError(CoreGeolocationErrorReason.PERMISSION_DENIED); } @@ -94,6 +106,8 @@ export class CoreGeolocationProvider { */ protected async doAuthorizeLocation(failOnDeniedOnce: boolean = false): Promise { const authorizationStatus = await Diagnostic.getLocationAuthorizationStatus(); + this.logger.log(`Authorize location: status ${authorizationStatus}`); + switch (authorizationStatus) { case Diagnostic.permissionStatus.DENIED_ONCE: if (failOnDeniedOnce) { @@ -101,7 +115,9 @@ export class CoreGeolocationProvider { } // Fall through. case Diagnostic.permissionStatus.NOT_REQUESTED: + this.logger.log('Request location authorization.'); await this.requestLocationAuthorization(); + this.logger.log('Location authorization granted.'); await CoreApp.waitForResume(500); await this.doAuthorizeLocation(true);