Hi All, I found a solution to fix it.
I recognized that this issue is raised when we do not setup timeout then onError function cannot fire when GPS service is OFF. So that I did to fix
-
Install plugin : diagnostic
ionic plugin add cordova.plugins.diagnostic.api-22
-
Update source code:
if (window.cordova) {
cordova.plugins.diagnostic.isLocationEnabled(function(enabled) {
console.log("Location is " + (enabled ? “enabled” : “disabled”));
if (enabled){
navigator.geolocation.getCurrentPosition(onSuccess, onErrore, { maximumAge: 3000, timeout: 120000, enableHighAccuracy: true})
} else {
//Navigator user to setting page
cordova.plugins.diagnostic.switchToLocationSettings();
}
}, function(error) {
alert("The following error occurred: " + error);
});
}
-
Go to build and check
1 Like
Anyone found a solution for this problem. i been stuck !!
your answer was helpfull, is there any way you show the same with wifi
This one worked for me 
Source : github
import { Component } from '@angular/core';
import { Geolocation } from '@ionic-native/geolocation';
import { Platform } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(private geolocation: Geolocation, private platform: Platform) {}
getLocation() {
this.platform.ready().then(()=>{
this.geolocation.getCurrentPosition().then((resp) => {
let lat = resp.coords.latitude;
let long = resp.coords.longitude;
console.log(lat,long);
}).catch((error) => {
console.log('Error getting location', error);
});
})
}
}
vorya
26
i have same issue, has anyone solution?
it not working not function getCurrentPosition not fire?
sir are u fixed above issue?