如何在 react-native-maps 中计算当前区域的尺寸?

How can I calculate the dimensions of the current region in react-native-maps?

latitude: 38.69444432847513
latitudeDelta: 0.1288559458782288
longitude: -90.5969550254043
longitudeDelta: 0.1638044205986091

假设我的地图区域有上面的数据(我使用onRegionChange)

如何获取当前区域的距离(直径),以千米为单位? (宽度会小于高度,因为phone是纵向模式)

我可以做一个简单的转换吗?

Definition of latitudeDelta:

The amount of north-to-south distance (measured in degrees)

因此,您可以简单地将 latitudeDelta 乘以 111 以获得近似高度(如果高度 > 宽度,则应该是直径)。

如果您需要宽度,公式会稍微复杂一些,因为它取决于纬度:

longitudeDelta * 40075 * cos(latitude) / 360

如果您需要非常精确的直径值,可以使用 Haversine formula or Vincenty's formulae,您可以自己实现或使用 npm 模块。
公式的两点是 (latitude - latitudeDelta / 2, longitude)(latitude + latitudeDelta / 2, longitude).