Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am practicing classes in javascript, in java I can use getters and setters. Ive tried that in Javascript but I am sure if I am doing it right. Any advice ya could give me would be great.

JavaScript
class Geolocation {
	constructor() {
		navigator.geolocation.getCurrentPosition(this.setCurrentPosition.bind(this));
		this.latitude = 0;
	}

	setCurrentPosition(position) {
		this.setLatitude(position.coords.latitude);
	}

	setLatitude(latitude) {
		this.latitude = latitude;
	}

	getLatitude() {
		return this.latitude;
	}
}


What I have tried:

I have tried setting both the lat and long to an array and assigning the index to
this.latitude
, and calling the getter.
Posted
Comments
Maciej Los 17-Apr-20 1:30am    
You mean you want to store an array of LAT and LONG in a Geolocation class... Am i right?
Member 14804508 17-Apr-20 8:04am    
Yes, then use it in other parts of the program

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900