簡體   English   中英

縮放到指定的標記react-native-maps

[英]Zoom to specified markers react-native-maps

react-native-maps文檔中有一個部分用於縮放到標記數組,但是在docs或examples文件夾中沒有關於如何執行此操作的代碼示例(我可以找到)

誰能提供一個如何做到這一點的例子?

在MapView組件文檔中,有幾種方法: fitToElementsfitToSuppliedMarkersfitToCoordinates https://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>
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM