Geolocation is not working in ionic 2


#1

im developing an ionic 2 app, i have a problem with geolocation it is not working on real device, when i check on browser its working but sometime even on browser latitude return null. i think this is timing problem, but i dont know to solve it if anyone can help

	MyLocation(){
      let options = {enableHighAccuracy: true};
            this.geolocation.getCurrentPosition(options).then((resp) => {
			console.log(resp.coords.altitude);
			console.log(resp.coords.longitude);
							
            }).catch((error) => {
            alert(JSON.stringify(error));
            });
  }

#2

You can use this cordova geolocation plugin -:

cordova-plugin-geolocation

You can also try this code this may help you

  var location = navigator.geolocation.getCurrentPosition(
    (position) => {
        console.log(position);
    },
    (error) =>{
        console.log(error);
    }, 
    { 
      enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 
    },
);

#3

Thank you for your reply i have tried already but not working it return just this {}