[英]Zoom to specified markers react-native-maps
react-native-maps文檔中有一個部分用於縮放到標記數組,但是在docs或examples文件夾中沒有關於如何執行此操作的代碼示例(我可以找到)
誰能提供一個如何做到這一點的例子?
在MapView組件文檔中,有幾種方法: fitToElements
, fitToSuppliedMarkers
和fitToCoordinates
。 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.