@iscorobogaci wrote:
Geolocation is giving such error.
getUserPosition() { return new Promise(resolve => { const HIGH_ACCURACY = 'high_accuracy'; if (this.platform.is('cordova')) { console.log('Platform is cordova'); this.platform.ready().then(() => { console.log('Platform is ready'); this.diagnostic.isLocationEnabled().then(enabled => { console.log('Location is enabled: ' +enabled); if (enabled) { if (this.platform.is('android')) { console.log('Platform is android'); this.diagnostic.getLocationMode().then(locationMode => { console.log('Location Mode : ' + locationMode); if (locationMode === HIGH_ACCURACY) { this.geo.getCurrentPosition({ timeout: 30000, maximumAge: 0, //was 0 enableHighAccuracy: false //was true }).then(pos => { resolve({ coords: { latitude: pos.coords.latitude, longitude: pos.coords.longitude } }); }).catch(error => resolve(error)); } else { this.askForHighAccuracy().then(available => { console.log('High Accuracy is available : ' + available); if (available) { this.getUserPosition().then(a => resolve(a), e => resolve(e)); } }, error => resolve(error)); } }); } else { this.geo.getCurrentPosition({ timeout: 30000, maximumAge: 0, enableHighAccuracy: true }).then(pos => { resolve({ coords: { latitude: pos.coords.latitude, longitude: pos.coords.longitude } }); }).catch(error => resolve(error)); } } else { this.locationAccuracy.request(1).then(result => { console.log('Location accuracy : ' + result); if (result) { this.getUserPosition().then(result => resolve(result), error => resolve(error)); } }, error => { resolve(error) }); } }, error => { resolve(error) }); }); //user on browser } else { //resolve('Cordova is not available'); resolve(this.geo.getCurrentPosition()); } }); } askForHighAccuracy(): Promise<Geoposition> { return new Promise(resolve => { this.locationAccuracy .request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(() => { this.geo.getCurrentPosition({timeout: 30000}).then( position => { resolve(position); }, error => resolve(error) ); }, error => resolve(error)); }); }
failing with timeout :
this.geo.getCurrentPosition({ timeout: 30000, maximumAge: 0, //was 0 enableHighAccuracy: false //was true }).then(pos => { resolve({ coords: { latitude: pos.coords.latitude, longitude: pos.coords.longitude } }); }).catch(error => resolve(error));
Issue on android devices , any help ?
Posts: 1
Participants: 1