5

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.

Charles Jr
  • 8,333
  • 15
  • 53
  • 74

2 Answers2

4

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)
Avt
  • 16,927
  • 4
  • 52
  • 72
  • Why do you us 50 * 1609.34 to make latitude and longitude distance in meters? – Charles Jr Dec 18 '16 at 01:11
  • 3
    @CharlesJr: 1609.34 is 1 mile in meters, so Avt is converting your 50 miles to the meters equivalent used for `CLLocationDistance`. – leanne Dec 18 '16 at 01:51
4

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)
leanne
  • 7,940
  • 48
  • 77