Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKCoordinateSpan in Meters?

People also ask

What is MKCoordinateSpan?

MKCoordinateSpan is the width and height of the map view in degrees, namely the latitudeDelta and longitudeDelta.

What is MKCoordinateSpan in Swift?

Creates a coordinate span that represents a width and height on a map.


Another alternative is to use MapKit's MKCoordinateRegionMakeWithDistance function:

MKCoordinateRegion rgn = MKCoordinateRegionMakeWithDistance(
    CLLocationCoordinate2DMake(someLatitude, someLongitude), 500, 500);

The MKCoordinateSpan will be in rgn.span.


Unless you need great accuracy you can make it much easier with approximation. The first problem is to find the fraction of a degree of latitude representing 500 meters. Easy since a degree of latitude is a constant in any location, roughly 111 km. So 500 meters is .0045 degrees latitude.

Then it gets harder because length of a degree of longitude varies depending on where you are. It can be approximated with

enter image description here

where alpha is earth's equatorial radius, 6,378,137km, b/a is 0.99664719 (a constant in use for the WGC84 spheroid model in use by all GPS devices) and enter image description here where phi is the degree of latitude.

Imagine for a second you're lucky enough to be in Melbourne with a longitude of 37.783 degrees S. North or South doesn't matter here. beta works out to be 37.6899 and the rest of it solves to give a longitudinal degree a length of 88km. So 500 meters is .0057 of a degree.

Result for Melbourne - MKCoordinateSpan melbourne500MeterSpan = MKCoordinateSpanMake(.0045, .0057);

You can check your answers and your code with this online calculator

The wiki article on longitude has a lot more detail on this (and it the source of the images here)

Code:

#define EARTH_EQUATORIAL_RADIUS (6378137.0)
#define WGS84_CONSTANT (0.99664719)

#define degreesToRadians(x) (M_PI * (x) / 180.0)

// accepts decimal degrees. Convert from HMS first if that's what you have
double spanOfMetersAtDegreeLongitude(double degrees, double meters) {

    double tanDegrees = tanf(degreesToRadians(degrees));
    double beta =  tanDegrees * WGS84_CONSTANT;
    double lengthOfDegree = cos(atan(beta)) * EARTH_EQUATORIAL_RADIUS * M_PI / 180.0;
    double measuresInDegreeLength = lengthOfDegree / meters;
    return 1.0 / measuresInDegreeLength;
}