I am trying to get the coords from the browser, then set them in the
this.longitude
but I am getting the error
geolocation.js:13 Uncaught TypeError: Cannot read property 'coords' of undefined at Geolocation.setCurrentPosition (geolocation.js:13) at main.js:39
I am not sure how to fix this issue. Any guidance so that I can better learn would be greatly appreciated!
class Geolocation {
constructor() {
this.latitude = 0;
this.longitude = 0;
}
getGeoLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(this.setCurrentPosition.bind(this), error());
}
}
setCurrentPosition(position) {
var crd = position.coords;
this.setLatitude(crd.latitude);
this.setLongitude(crd.longitude);
console.log('Your current position is:');
console.log(`Latitude : ${crd.latitude}`);
console.log(`Longitude: ${crd.longitude}`);
}
error() {
ui.showError();
}
setLatitude(latitude) {
this.latitude = latitude;
}
setLongitude(longitude) {
this.longitude = longitude;
}
getLatitude() {
console.log(this.latitude);
return this.latitude;
}
getLongitude() {
return this.longitude;
}
}