动态Lat Lang在MapView中的react-native

时间:2017-10-03 14:08:22

标签: google-maps react-native android-mapview expo

使用expo MapView。我正在搜索如何根据手机的高度和宽度查找纬度和平台的解决方案。 Ex :{{1 }。 here i attached the screenshot

有人可以帮助/澄清我。

1 个答案:

答案 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的图片)

example of delta points

使用此信息,您可以计算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);