【问题标题】:How to enable centering Marker on Map in IOS using React native?如何使用 React native 在 IOS 中的地图上启用居中标记?
【发布时间】:2021-02-02 02:23:21
【问题描述】:

我正在使用来自 react-native-maps 的 Map 组件,并且我在其中显示了许多标记,但是每当在 Android 上单击标记时,单击的标记会自动居中,而这种行为在IOS.

有没有办法让标记在 IOS 中也居中,或者至少在 Android 中禁用它。 我希望在两个操作系统中具有相同的行为。

任何帮助或想法将不胜感激。

【问题讨论】:

  • 请 :) 需要帮助的人

标签: android ios react-native compatibility react-native-maps


【解决方案1】:

你可以设置

<MapView
moveOnMarkerPress={false}
...
/>

这将禁用 android 行为,或者您可以在 iOS 上处理 MarkerPress 并将 MapView 居中,如下所示:

 <MapView
    ...
    ref={ref => {
       this.map = ref;
    }}
    >
      {this.state.markers.map(marker => (
        <Marker
          ...
          onSelect=(({coordinate}) =>  this.map.animateCamera({center: coordinate}, { duration: 2000 }))
        />
      ))}
    </MapView>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-04
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 2015-12-02
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多