I am willing to get the value of the function outside of it; however, I am getting undefined
here is the below code:
getCoords() {
let call = this.http.get('https://maps.googleapis.com/maps/api/geocode/json?address=' + address + '&key=' + this.key).subscribe(data => {
let lat = data.json().results[0].geometry.location.lat;
let long = data.json().results[0].geometry.location.lng;
this.latLong = {
"lat": lat,
"long": long
};
//I can get it here
console.log('called >> ', this.latLong)
return this.latLong;
});
//this.latlong is undefined !
}
//if I call getCoords() here I get undefined too