I've been working on crafting a geolocation class to have ready for when I need it, but I've hit a snag and keep encountering this error message:
Uncaught TypeError: Cannot read property 'setLatitude' of undefined
at setCurrentPosition (geolocation.js:13)
Any tips or advice on how to proceed?
class Geolocation {
constructor() {
this.latitude = 0;
this.longitude = 0;
}
getGeoLocation() {
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(this.setCurrentPosition);
}
}
setCurrentPosition(position) {
this.setLatitude(position.coords.latitude);
this.setLongitude(position.coords.longitude);
}
setLatitude(latitude) {
this.latitude = latitude;
}
setLongitude(longitude) {
this.longitude = longitude;
}
getLatitude() {
return this.latitude;
}
getLongitude() {
return this.longitude;
}
}