I am working on geofencing where I have to do region monitoring. I am new to geofence topic. I have bounds
(min-max coordinates) and geometry
data(all location coordinates). From the below bounds
, I am creating CLCircularRegion
.
"bounds":{"minlat":50.7238333,"minlon":-1.8716499,"maxlat":50.7248599,"maxlon":-1.8683962}
To initialise CLCircularRegion
, we need center
and radius
. I have calculated centerpoint
using the following formula:
center = CLLocationCoordinate2D(latitude: CLLocationDegrees((minLat + maxLat) / 2), longitude: CLLocationDegrees((minLng + maxLng) / 2))
But I am unable to understand how to calculate radius. Any Idea how to do that?
You only have to calculate the distance from center to a point. Use CLLocation method distance(from:). You can create CLLocation instances with latitude and longitude.