How can I return the value in API to a function in React Native
Here is my code
getTime = async (lat1, lng1, lat2, lng2) => {
let URL = 'https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins='+lat1+','+lng1+'&destinations='+lat2+'%2C'+lng2+'&key=' + GOOGLE_MAPS_APIKEY;
let response = await fetch(URL)
let responseJson = await response.json()
return responseJson
}
Here is the function I try to call it
callTime = () => {
let a = await this.getTime(lat1, lng1, lat2, lng2)
.then(response => response.rows[0].elements[0].duration.value)
return a
}
When I try to console.log callTime, the value is {"_U": 0, "_V": 0, "_W": null, "_X": null}
I have try with fetch API always returns {"_U": 0, "_V": 0, "_W": null, "_X": null} and LOG {"_U": 0, "_V": 0, "_W": null, "_X": null} inside fetch API but it's not work for me
Hope someone can help me with this problem, it's for my final task in college