Hallo React and Js programmer, I have a question related to function's scoop or variable
I have this code here to get the Postion from gecoder
getPosition = pos => {
let address;
Geocoder.reverseGeocode(pos.latitude, pos.longitude, (err, geoData) => {
if (!err) {
const data = (geoData.results[0].formatted_address);
address = data;
}
}, apiKey);
console.log(address);// undefined
}
and I tried to use an array and push the result inside it
const address = [];
Geocoder.reverseGeocode(pos.latitude, pos.longitude, (err, geoData) => {
if (!err) {
const data = (geoData.results[0].formatted_address);
address.push(data);
}
}, apiKey);
console.log(address[0]);
is there any way to get the value from the data which is a string ? thanks