Ionic Geolocation
I am attempting to write an app that uses geolocation to get the user’s position when they open up the app. I read that the geolocation services used by the phone and computer are the same, so testing geolocation on the computer is viable.
I have this block of code:
getPosition() {
console.log("Getting Position");
this.geolocation.getCurrentPosition().then((resp) => {
console.log("position = ");
this.lat = resp.coords.latitude;
this.long = resp.coords.longitude;
}).catch((error) => {
console.log("Error getting position");
this.testVar = 10;
});
console.log("After position block");
let watchT = this.geolocation.watchPosition();
watchT.subscribe((data) => {
//this.latitude = data.coords.latitude;
//this.longitude = data.coords.longitude;
});
}
And when I run it in the browser and check the console, "Getting position" and "After position block" both print, but neither do "position = " or "Error getting position" print. I figured one of those would have to print based on whether it succeeded or failed.
What am I doing wrong here? Am I wrong in assuming I can test the geolocation on the computer?
Source: AngularJS Questions