Trying to get the span size in meters for an iOS MKCoordinateSpan
Swift implementation for Hanne's solution:
let span = mapView.region.span
let center = mapView.region.center
let loc1 = CLLocation(latitude: center.latitude - span.latitudeDelta * 0.5, longitude: center.longitude)
let loc2 = CLLocation(latitude: center.latitude + span.latitudeDelta * 0.5, longitude: center.longitude)
let loc3 = CLLocation(latitude: center.latitude, longitude: center.longitude - span.longitudeDelta * 0.5)
let loc4 = CLLocation(latitude: center.latitude, longitude: center.longitude + span.longitudeDelta * 0.5)
let metersInLatitude = loc1.distanceFromLocation(loc2)
let metersInLongitude = loc3.distanceFromLocation(loc4)
EDIT:
For Swift 5 distanceFromLocation(_:)
has been renamed to distance(from:)
meaning that the two last lines now read
let metersInLatitude = loc1.distance(from: loc2)
let metersInLongitude = loc3.distance(from: loc4)
As I can see you already have the region of the map. It doesn't only contain the lat & long deltas but also the center point of the region. You can calculate the distances in meters as illustrated in the picture:
1: Get the region span (how big the region is in lat/long degrees)
MKCoordinateSpan span = region.span;
2: Get the region center (lat/long coordinates)
CLLocationCoordinate2D center = region.center;
3: Create two locations (loc1 & loc2, north - south) based on the center location and calculate the distance inbetween (in meters)
//get latitude in meters
CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:(center.latitude - span.latitudeDelta * 0.5) longitude:center.longitude];
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:(center.latitude + span.latitudeDelta * 0.5) longitude:center.longitude];
int metersLatitude = [loc1 distanceFromLocation:loc2];
4: Create two locations (loc3 & loc4, west - east) based on the center location and calculate the distance inbetween (in meters)
//get longitude in meters
CLLocation *loc3 = [[CLLocation alloc] initWithLatitude:center.latitude longitude:(center.longitude - span.longitudeDelta * 0.5)];
CLLocation *loc4 = [[CLLocation alloc] initWithLatitude:center.latitude longitude:(center.longitude + span.longitudeDelta * 0.5)];
int metersLongitude = [loc3 distanceFromLocation:loc4];
Based on the above, here's a useful extension I use in my mapping projects:
extension MKCoordinateRegion {
public var radius: CLLocationDistance {
let loc1 = CLLocation(latitude: center.latitude - span.latitudeDelta * 0.5, longitude: center.longitude)
let loc2 = CLLocation(latitude: center.latitude + span.latitudeDelta * 0.5, longitude: center.longitude)
let loc3 = CLLocation(latitude: center.latitude, longitude: center.longitude - span.longitudeDelta * 0.5)
let loc4 = CLLocation(latitude: center.latitude, longitude: center.longitude + span.longitudeDelta * 0.5)
let metersInLatitude = loc1.distance(from: loc2)
let metersInLongitude = loc3.distance(from: loc4)
let radius = max(metersInLatitude, metersInLongitude) / 2.0
return radius
}
}