Google 在 React Native 地图中按住拖动时地图标记移动错误

Google map marker moves wrongly when I holding to press for drag in react native maps

我想在 React Native 地图视图中拖动一个标记。
拖动还可以,但第一次按下标记时,它会向上方移动一点。
我想修复这个意外的举动。
不知道是什么原因。
您可以查看当前情况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

此行为也显示在 react-native-maps 的 DraggableMarkers.js example 中,因此您的代码实现不是此处的问题。

它可能已经在 GitHub 存储库中报告过,但我无法找到它,所以我建议您为此 here.

提交错误

希望对您有所帮助!