admin管理员组

文章数量:1346298

I'm trying to retrieve distance information between two locations. informations like time, value e.t.c. this works while texting on iPhone but on android it returns undefined. I've tried two approaches to make it work on android, the first was to save it to a redux store and retrieve it like so

 const traveleTimeInformation = useSelector(selectTravelTimeInformation)
 const time = traveleTimeInformation?.duration.text!
 const durationValue = traveleTimeInformation?.duration.value!

the second was get it directly on same page and save it to a useState like so

const [rideTime, setRideTime] = useState(time)
const [rideDuration, setRideDuration] = useState(durationValue)

 useEffect(() => {
const interval = setInterval(() => {
  refreshSearch();
}, 2000);

return () => {
  clearInterval(interval);
};
},[refreshSearch])

 async function refreshSearch() {
 await fetch(`?
  units=imperial&origins=
  ${userAddress}&destinations=
  ${destinationAddress}&key=
  ${process.env.EXPO_PUBLIC_GOOGLE_API_KEY}`)
  .then((res) => res.json())
  .then(data => {
  console.log('testing time', data.rows[0].elements[0].duration.text!)
  setRideTime(data.rows[0].elements[0].duration.text!)
  setRideDuration(data.rows[0].elements[0].duration.value!)
})

}

all this works while on iOS but on android it returns Cannot read property 'text' of undefined

I tried to console log the result but it seems at first it returns undefined before returning the actual value

本文标签: react nativefetch google maps distance matrix not working on androidStack Overflow