Skip to content

Commit 15a9c74

Browse files
authored
Merge pull request #3561 from dpalou/MOBILE-4239
MOBILE-4239 geolocation: Add some logging in geolocation service
2 parents b7db250 + f0aa3ee commit 15a9c74

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/core/services/geolocation.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ import { CoreUtils } from './utils/utils';
2222
import { CorePlatform } from './platform';
2323
import { CoreSilentError } from '@classes/errors/silenterror';
2424
import { CoreSubscriptions } from '@singletons/subscriptions';
25+
import { CoreLogger } from '@singletons/logger';
2526

2627
@Injectable({ providedIn: 'root' })
2728
export class CoreGeolocationProvider {
2829

30+
protected logger: CoreLogger;
31+
32+
constructor() {
33+
this.logger = CoreLogger.getInstance('CoreGeolocationProvider');
34+
}
35+
2936
/**
3037
* Get current user coordinates.
3138
*
@@ -34,16 +41,21 @@ export class CoreGeolocationProvider {
3441
*/
3542
async getCoordinates(): Promise<Coordinates> {
3643
try {
44+
this.logger.log('Getting coordinates.');
3745
await this.authorizeLocation();
3846
await this.enableLocation();
47+
this.logger.log('Getting coordinates: authorized and enabled.');
3948

4049
const result = await Geolocation.getCurrentPosition({
4150
enableHighAccuracy: true,
4251
timeout: 30000,
4352
});
53+
this.logger.log('Coordinates retrieved');
4454

4555
return result.coords;
4656
} catch (error) {
57+
this.logger.log('Error getting coordinates.', error);
58+
4759
if (this.isCordovaPermissionDeniedError(error)) {
4860
throw new CoreGeolocationError(CoreGeolocationErrorReason.PERMISSION_DENIED);
4961
}
@@ -94,14 +106,18 @@ export class CoreGeolocationProvider {
94106
*/
95107
protected async doAuthorizeLocation(failOnDeniedOnce: boolean = false): Promise<void> {
96108
const authorizationStatus = await Diagnostic.getLocationAuthorizationStatus();
109+
this.logger.log(`Authorize location: status ${authorizationStatus}`);
110+
97111
switch (authorizationStatus) {
98112
case Diagnostic.permissionStatus.DENIED_ONCE:
99113
if (failOnDeniedOnce) {
100114
throw new CoreGeolocationError(CoreGeolocationErrorReason.PERMISSION_DENIED);
101115
}
102116
// Fall through.
103117
case Diagnostic.permissionStatus.NOT_REQUESTED:
118+
this.logger.log('Request location authorization.');
104119
await this.requestLocationAuthorization();
120+
this.logger.log('Location authorization granted.');
105121
await CoreApp.waitForResume(500);
106122
await this.doAuthorizeLocation(true);
107123

0 commit comments

Comments
 (0)