latitude: 38.69444432847513
latitudeDelta: 0.1288559458782288
longitude: -90.5969550254043
longitudeDelta: 0.1638044205986091
Suppose my map region has the data above (I use onRegionChange)
How can I get the distance (diameter) of the current region, in kilometers? (the width will be smaller than the height, because the phone is in portrait mode)
Is there an easy conversion I can do?
Definition of latitudeDelta:
The amount of north-to-south distance (measured in degrees)
Hence you can simply multiply latitudeDelta
by 111
to get the approximate height (which should be the diameter if height > width).
If you need the width, the formula is slightly more complicated as it's dependent on the latitude:
longitudeDelta * 40075 * cos(latitude) / 360
If you need a very precise value of the diameter, you can use the Haversine formula or Vincenty's formulae, which you can implement yourself or use an npm module.
The two points for the formula will be (latitude - latitudeDelta / 2, longitude)
and (latitude + latitudeDelta / 2, longitude)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With