在GitHub上的react-native-maps仓库提供的示例中,展示了一个按钮来执行函数,根据标记列表设置适当的缩放:
fitAllMarkers() {
this.map.fitToCoordinates(MARKERS, {
edgePadding: DEFAULT_PADDING,
animated: true,
});
}
https://github.com/airbnb/react-native-maps/blob/master/docs/mapview.md
如果已经初始化了一个标记点数组,能否使用适当的坐标显示来初始化地图?
当尝试在componentDidMount
中设置正确的适应大小时,我收到以下错误信息:
Error using new LatLntBounds(LatLngBounds, int): Map size can't be 0. Most likely, layout has not yet occured for the map view
。
显然,在调用我的fitAllMarkers()
函数之前太早了。是否有一个onLoad
函数可以在地图初始化后立即触发?