getCurrentPosition not working after turning the GPS off on the device even if it turned on again?

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

  1. Install plugin : diagnostic
    ionic plugin add cordova.plugins.diagnostic.api-22

  2. 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);
    });
    }

  3. 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 :slight_smile:

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);
	});
     })
  }

}

i have same issue, has anyone solution?

anyone fix above issue?

it not working not function getCurrentPosition not fire?

sir are u fixed above issue?