Search code examples
swiftgeolocationcllocationmanagermkcoordinateregion

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


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.


Solution

  • 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)