I am using google.maps.geocoder to get a location request in my angular app. In a request I provide a callback function with results. now if I want to call my other function which displays the marker on map the code breaks unexpectedly. I also can not set any variables defined on my component, it looks like every global variable/function is undefined when the code in the Geocoder callback function is happening.
How can I fix this and get data from my callback function in my app?
googleMapsFindLocation() {
var address = this.locationName;
this.geocoder.geocode({ 'address': address }, function (results, status) {
if (status == 'OK') {
var mapCustomObj = new MapCustomObj();
var marker = {
position: { lat: 46, lng: 16 },
info:
'<h2>' + "tekst" + '</h2></br>' +
'<p>' + "" + '</p>' +
'<p>' + "this.raceDto.seasonName" + '</p>' +
'<p>' + "this.raceDto.lat" + ' - ' + "this.raceDto.long" + '</p>'
};
mapCustomObj.marker = marker;
//HERE IS THE PROBLEM. If i call showMap the code breaks, and the code in my showMap doesnt even get hit in debug
this.showOnMap(mapCustomObj);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}