How to create an MKCoordinate region similar to 50 miles radius in ios Swift?

2.8k views Asked by At

I'm trying to create a region similar to a circle radius using CLLocation. I understand radius logic and how its measured in meters, but not so clear on a MKCoordinate region and how long delta and lat delta translate to area. I would like to get a 75 mile region. Here is my code....

let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

If you could please provide an explanation more than just a short answer it would be appreciated.

2

There are 2 answers

0
leanne On BEST ANSWER

If you're trying to create an actual circular region:

let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let radius: CLLocationDistance = 60350.4    // meters for 37.5 miles
let regionIdentifier = "CircularRegion"     // any desired String

let circularRegion = CLCircularRegion(center: center, radius: radius, identifier: regionIdentifier)
2
Avt On

You could use MKCoordinateRegionMakeWithDistance function:

Creates a new MKCoordinateRegion from the specified coordinate and distance values.

func MKCoordinateRegionMakeWithDistance(
_ centerCoordinate: CLLocationCoordinate2D, 
_ latitudinalMeters: CLLocationDistance, 
_ longitudinalMeters: CLLocationDistance) -> MKCoordinateRegion

centerCoordinate - The center point of the new coordinate region.

latitudinalMeters - The amount of north-to-south distance (measured in meters) to use for the span.

longitudinalMeters - The amount of east-to-west distance (measured in meters) to use for the span.

So you will have something like:

let rect = MKCoordinateRegionMakeWithDistance(center, 50 * 1609.34, 50 * 1609.34)