在 React Native 中滚动地图时如何在地图上拖动点

How to drag point on maps when scroll the map in react native

enter image description here我愿意在我的应用程序中使用此功能,当我滚动地图时标记会自动拖动,就像在 uber 和 careem 应用程序中一样。

您可以使用图像或图标创建客户标记,然后您可以使用

   <MapView   
     ....
     onRegionChangeComplete={(region) => {
                  this.setLocation(region);}>

然后您可以在滚动时设置更新的区域。

 setLocation = (region) => {
try {
  if (region && region.longitude !== 0) {
    const latitude = region.latitude;
    const longitude = region.longitude;
    if (
      latitude.toFixed(6) == this.state.region.latitude.toFixed(6) &&
      longitude.toFixed(6) == this.state.region.longitude.toFixed(6)
    ) {
      return false;
    } else {
      this.setState({region}, () => {
        console.log('New Region', this.state.region);
      });
    }
  }
} catch {
  Alert.alert('App name', 'Location Permission not granted');
}

};

这可能对您有所帮助。