【问题标题】:Google map marker moves wrongly when I holding to press for drag in react native maps当我按住以拖动反应原生地图时,谷歌地图标记移动错误
【发布时间】:2020-04-11 12:01:34
【问题描述】:

我想在 react native mapview 中拖动一个标记。
拖动是可以的,但是当我第一次按下标记时,它会向上方移动一点。
我想解决这个意外的举动。
我不确定是什么原因。
您可以查看当前情况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

【问题讨论】:

    标签: reactjs react-native google-maps android-emulator react-native-maps


    【解决方案1】:

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

    它可能已经在 GitHub 存储库上报告过,但我找不到它,所以我建议你为此 here 提交一个错误。

    希望这会有所帮助!

    【讨论】:

    • 感谢您的帮助。我想知道您对解决此错误的意见。
    • 不客气! :) 我不开发或使用该库,所以很遗憾我无法帮助您自己解决该错误,但如果您为此提交错误,那么库的开发人员或贡献者可能会修复它。
    猜你喜欢
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 2017-09-21
    • 2019-05-19
    • 2012-08-07
    • 2011-08-07
    • 2016-08-30
    • 1970-01-01
    相关资源
    最近更新 更多