答案 0 :(得分:2)
当您从MapView
通过onRegionChange
或任何其他类似事件获得区域对象时,该对象包含4个属性。
示例强>
const region = {
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}
增量值是指您想要显示的最小点和最大点之间的差异。
(来自MKMapView and Zoom Levels: A Visual Guide的图片)
使用此信息,您可以计算MapView的4个角(地图边界),或者您可以使用它们来设置缩放级别。
示例 (未经过测试,因此计算时可能会出现错误)
如果我们在下面的示例中给出了MapView
区域,我们的四个角将是下面计算的位置。
const leftTopLongitude = region.longitude - (region.longitudeDelta / 2);
const rightTopLongitude = region.longitude + (region.longitudeDelta / 2);
const leftTopLatitude = region.latitude + (region.latitudeDelta / 2);
const rightTopLatitude = region.latitude + (region.latitudeDelta / 2);
const leftBottomLongitude = region.longitude - (region.longitudeDelta / 2);
const rightBottomLongitude = region.longitude + (region.longitudeDelta / 2);
const leftBottomLatitude = region.latitude - (region.latitudeDelta / 2);
const rightBottomLatitude = region.latitude - (region.latitudeDelta / 2);