我正在使用 ionic native geocoder 从字符串中获取坐标。Country 是为国家/地区提供的字符串。坐标从下面的代码给出所需的纬度和经度。变量坐标数据给出包含函数内部纬度和经度的实际结果。如果我尝试在函数外打印坐标数据,它会给出未定义。
this.nativeGeocoder.forwardGeocode(Country).then((coordinates: NativeGeocoderForwardResult[])=> {
let 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
当我进入函数内部时,我希望从函数外部的变量坐标数据获得相同的结果。
SMILET
相关分类