gpt4 book ai didi

reactjs - react native "Value for longitude cannot be cast from String to Double"

转载 作者:行者123 更新时间:2023-12-05 09:13:59 25 4
gpt4 key购买 nike

我正在使用 react-native-maps 并且我使用这段代码得到了纬度和经度:

callLocation(that) {
navigator.geolocation.getCurrentPosition(
position => {
const currentLongitude = JSON.stringify(position.coords.longitude);
const currentLatitude = JSON.stringify(position.coords.latitude);
that.setState({ currentLongitude: currentLongitude });
that.setState({ currentLatitude: currentLatitude });
},
error => alert(error.message),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
that.watchID = navigator.geolocation.watchPosition(position => {
console.log(position);
const currentLongitude = JSON.stringify(position.coords.longitude);
const currentLatitude = JSON.stringify(position.coords.latitude);
that.setState({ currentLongitude: currentLongitude });
that.setState({ currentLatitude: currentLatitude });
});
}

这是我的 map View 代码:

<MapView
style={styles.map}
initialRegion={{
latitude: this.state.currentLatitude,
longitude: this.state.currentLongitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}
/>

当我在我的代码中粘贴这个纬度和经度时,出现以下错误:

最佳答案

没有比像这样解析坐标位置更容易的了:

{
latitude: parseFloat(myObj.latitude),
longitude: parseFloat(myObj.longitude)
}

关于reactjs - react native "Value for longitude cannot be cast from String to Double",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55138691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com