我用大react-native-maps
来自 Airbnb 上的 react-native
应用程序。
我在 JSON 文件中得到了一个标记列表,其中每个标记都有一个属性 zoom
这是标记应在 map 上显示/隐藏的近似缩放级别的整数。
有没有基于latitudeDelta
的方法和 longitudeDelta
的 Region
获得当前缩放级别的近似两倍/整数,就像我们在 Google map 上(1 到 20)一样?
谢谢
最佳答案
好的,我有一个方便的解决方案,我不知道我们是否可以做得更好。
我添加了 onRegionChange
事件来检索区域,然后我使用一些数学:
<MapView
style={styles.map}
initialRegion={this.state.region}
onRegionChange={region => {
clearTimeout(this.timerForMap)
this.timerForMap = setTimeout(() => {
this.showMarkers(region)
}, 100)
}}>
...
然后 :
showMarkers(region) {
let zoom = Math.round(Math.log(360 / region.longitudeDelta) / Math.LN2)
...
}
如果有人有更好的方法,请随时发表评论!
谢谢。
关于react-native - 将 Region latitudeDelta/longitudeDelta 转换成近似的 zoomLevel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46568465/