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
版权声明:本文标题:react native - fetch google maps distance matrix not working on android - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743828599a2546106.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论