我正在进行地理围栏工作,因此我必须进行区域监视。我是地理围栏的新手。我有bounds
(最小-最大坐标)和geometry
数据(所有位置坐标)。从下面的bounds
中创建CLCircularRegion
。
"bounds":{"minlat":50.7238333,"minlon":-1.8716499,"maxlat":50.7248599,"maxlon":-1.8683962}
要初始化CLCircularRegion
,我们需要center
和radius
。我已经使用以下公式计算了centerpoint
:
center = CLLocationCoordinate2D(latitude: CLLocationDegrees((minLat + maxLat) / 2), longitude: CLLocationDegrees((minLng + maxLng) / 2))
但是我无法理解如何计算半径。任何想法如何做到这一点?
您只需要计算中心到点的距离。使用CLLocation方法distance(from :)。您可以使用纬度和经度创建CLLocation实例。