First of all, I should say that I dont have a lot of experience working with TS/JS.
I am working on an angular project that requires me to find lat, long from a given address and use that value in a different component. I'm using the google geocoder service and my aim is to get lat, long from the results and store it in a global variable.
This is my service call:
var res = this.geocoder.geocode({address: this.address }, getGeoResults);
And this is the callback:
GeoLoc: any;
getGeoResults( results, status) {
if(status == google.maps.Geocoderstatus.OK) {
this.geoLoc = results
}
}
But the issue is that neither can I get the results from the service into 'res' variable as it returns a ZoneAwarePromise nor can I use any other global variable(GeoLoc) to store the results inside the callback function(error: Cannot set property of undefined) as it is an async function.
Please suggest any method either by getting results in res variable or by storing it in another global variable in the callback function. Or any other method where we can get data from a async callback.
Thank you!