When I need to make an MKCoordinateRegion
, I do the following:
var region = MKCoordinateRegion
.FromDistance(coordinate, RegionSizeInMeters, RegionSizeInMeters);
very simple - works perfectly.
Now I wish to store the value of the current region span. When i look at the region.Span
value, it’s an MKCoordinateSpan
which has two properties:
public double LatitudeDelta;
public double LongitudeDelta;
How can I convert the LatitudeDelta
value into a latitudinalMeters
please? (So then I can recreate my region (later on) using the above method...
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];
Swift implementation for Hannes 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)