How to pass new position of marker into a function?

#1

in fallowing code I want to pass dragged marker LatLng into a function to get address but it is not working

public LastLat : any; 
public LastLng : any; 
. . .

lastLatLng(marker){
  google.maps.event.addListener(marker, 'dragend', function() { 
  this.LastLat= marker.position.lat();
  this.LastLng= marker.position.lng();
  });

console.log(this.LastLat,this.LastLng);

      this.Getaddress(this.LastLat,this.LastLng);

}

Getaddress(LastLat, LastLng){
this.http.get('http://nominatim.openstreetmap.org/reverse?format=json&lat='+LastLat+ '&lon='+LastLng + '&zoom=18&addressdetails=1')
        .map(res => res.json())
        .subscribe(data => {
        this.data = data.display_name;
        console.log(this.data);
});
}
#2

9 times out of 10 that I see the word “function” in a question like this, I suspect an execution context problem.

1 Like