Problems using current position from Geolocation


#1

My problem is related to the use of the cordova geolocation in ionic-native. I’m not able to get the gps location successfully neither AVD nor in a device. I’am using Diagnostic and Geolocation plugins (they are added to the project and it should work ok)

some code below:

this.platform.ready().then(() => {
	Diagnostic.isGpsLocationEnabled().then( (gpsLocationEnabled)=>{
		if(gpsLocationEnabled){
			Diagnostic.isGpsLocationAvailable().then ( (gpsLocationAvailable)=>{
				if(gpsLocationAvailable){
					var options = {
						enableHighAccuracy : true,
						timeout : 5000,
						maximumAge : 0
					};
					Geolocation.getCurrentPosition(options).then((position) => {
						this.position = position;
						this.showAlert('app.position.success');
					});
				}else{
					this.showAlert('app.error.location');
				}
			}).catch( (error) => {
				this.showAlert('app.error.location');
			});
		}else{
			this.showAlert('app.error.gps.notenabled');
		}
	});
});

In my last approach I added the options variable but the error I get is a timeout error. I tryed to increase but still getting this error. I think the plugin can’t get the position from the device.

The conditionals are working ok. If the GPS button is swiched off the corresponding alert is shown and so on. So, anybody knows what could happen here?

I deploy the app using ‘’‘ionic build android’’’

Best regards


#2

This syntax leads me to believe you’re still using ionic-native v2. I would suggest moving to ionic-native v3. In addition to many bug fixes that may address your issue, it will significantly decrease your app binary size.