gpt4 book ai didi

reactjs - 当我按住 React Native map 进行拖动时,谷歌地图标记移动错误

转载 作者:行者123 更新时间:2023-12-04 15:36:57 27 4
gpt4 key购买 nike

我想在 React Native map View 中拖动一个标记。
可以拖动,但第一次按下标记时,它会向上方移动一点。
我想修复这个意外的举动。
我不确定是什么原因。 可以查看当前情况here .
源码如下。

import React, {useState, useEffect} from 'react'
import { View } from 'react-native'
import MapView, {Marker} from 'react-native-maps'

const DEFAULT_DELTA = {latitudeDelta: 0.015, longitudeDelta: 0.0121}

const initialLoc = {
latitude: 24,
longitude: 75
}

const App = () => {
const [location, setLocation] = useState(initialLoc)

useEffect(() => {
navigator.geolocation.watchPosition(
position => {
const {latitude, longitude} = position.coords;
setLocation({
latitude,
longitude
})
},
error => {
console.error(error)
}, {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 10000
}
);
}, [])

const onMarkPress = (e) => {
const {coordinate} = e.nativeEvent
setLocation(coordinate)
};

const onMapPress = (e) => {
const {coordinate} = e.nativeEvent
setLocation(coordinate)
};

return (
<View style={{flex:1}}>
{location && (
<MapView
style={{flex: 1}}
initialRegion={{
latitude: location.latitude,
longitude: location.longitude,
...DEFAULT_DELTA
}}
onPress={onMapPress}
>
<Marker draggable
coordinate={location}
onDragEnd={onMarkPress}
/>
</MapView>
)}
</View>
)
}

export default App

最佳答案

此行为也显示在 DraggableMarkers.js example 中react-native-maps,所以你的代码实现不是这里的问题。

它可能已经在 GitHub 存储库中报告过,但我没能找到它,所以我建议您为此提交一个错误 here .

希望这对您有所帮助!

关于reactjs - 当我按住 React Native map 进行拖动时,谷歌地图标记移动错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59400409/

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