【问题标题】:How to drag point on maps when scroll the map in react nativereact native滚动地图时如何在地图上拖动点
【发布时间】:2020-07-22 11:27:30
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

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

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

     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');
    }
    

    };

    这可能对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      相关资源
      最近更新 更多