缩放到指定的标记 react-native-maps

Zoom to specified markers react-native-maps

react-native-maps 文档中有一个部分用于缩放到标记数组,但是在文档或示例文件夹中没有代码示例说明如何执行此操作(据我所知找到)

任何人都可以提供如何执行此操作的示例吗?

在 MapView 组件文档中,有几个方法:fitToElementsfitToSuppliedMarkersfitToCoordinateshttps://github.com/airbnb/react-native-maps/blob/master/docs/mapview.md#methods

如果您想在加载时放大某些标记集合的地图,您可以在初始渲染后使用 componentDidMount 进行放大:

class SomeView extends Component {
    constructor() {
      this.mapRef = null;
    }

    componentDidMount() {
      this.mapRef.fitToSuppliedMarkers(
        someArrayOfMarkers,
        false, // not animated
      );
    }

    render() {
      <MapView
        ref={(ref) => { this.mapRef = ref }}
      >
        { someArrayOfMarkers }
      </MapView>
    }
}