Попробуй вот так. let
значения не будут доступны за пределами функции, поэтому используйте var
var coordinatesData= ""; //define the variable outside your call.
this.nativeGeocoder.forwardGeocode(Country).then((coordinates: NativeGeocoderForwardResult[])=> {
coordinatesData=JSON.stringify(coordinates, null, 2);
this.map.animateCamera( {
target: {
lat: coordinates[0].latitude,
lng: coordinates[0].longitude
}
, zoom: 4, duration: 500
}
);
let marker: Marker=this.map.addMarkerSync( {
position: {
lat: parseFloat(coordinates[0].latitude),
lng: parseFloat(coordinates[0].longitude)
}
, animation: GoogleMapsAnimation.DROP
}
);
}
) .catch((error: any)=> (error));
console.log(coordinatesData) // undefined
обновленный ответ:
var coordinatesData = this.nativeGeocoder.forwardGeocode(Country).then((coordinates: NativeGeocoderForwardResult[])=> {
this.map.animateCamera( {
target: {
lat: coordinates[0].latitude,
lng: coordinates[0].longitude
}
, zoom: 4, duration: 500
}
);
let marker: Marker=this.map.addMarkerSync( {
position: {
lat: parseFloat(coordinates[0].latitude),
lng: parseFloat(coordinates[0].longitude)
}
, animation: GoogleMapsAnimation.DROP
}
);
logData(JSON.stringify(coordinates, null, 2));
}
) .catch((error: any)=> (error));
function logData(coordinatesData){
console.log(coordinatesData) // undefined
}