I am new to the ES6. I am facing problem storing data in variable that is out of scope.I have created button event and associated getLocation()
to it to find users location but I am not able to find way to update lon, lat variables which are out of scope.
Bellow is the code :
lon: any;
lat: any;
getLocation() {
var lat;
var lon;
navigator.geolocation.getCurrentPosition(function(d) {
lat = d.coords.latitude.toFixed(2);
lon = d.coords.longitude.toFixed(2);
console.log(this.lat);
console.log(this.lon);
});
}
Update(lat: any, lon: any) {
this.lat = lat;
this.lon = lon;
}