i need to store position.coords.(latitude/longitude) inside an object declared outside of navigator.geolocation.getCurrentPosition().
async axiosRequest (usage) {
var options = {}
...
} else if (usage === 'gps') {
navigator.geolocation.getCurrentPosition((position) => {
options = {
method: 'GET',
url: 'https://api.waqi.info/feed/geo:' + position.coords.latitude + ';' + position.coords.longitude + '/',
params: {
token: process.env.VUE_APP_AICQN_API_KEY
}
console.log(options) // {...} that's work !!
}
});
console.log(options) // {} ???
}
...
try {
const response = await axios.request(options)
return response.data
} catch (error) {
console.error(error)
}
}
I don't understand why options is empty ( {} ) in the console.log(). How can I set options data inside the callback arrow function?
Thanks in advance!