How to check if MKCoordinateRegion contains CLLocationCoordinate2D without using MKMapView?

后端 未结 9 820
天涯浪人
天涯浪人 2020-12-13 05:08

I need to check if user location belongs to the MKCoordinateRegion. I was surprised not to find simple function for this, something like: CGRectContainsCGPoint(rect,

9条回答
  •  不知归路
    2020-12-13 05:20

    Works for me like a charm (Swift 5)

    func check(
        location: CLLocationCoordinate2D,
        contains childLocation: CLLocationCoordinate2D,
        with radius: Double)
        -> Bool
    {
        let region = CLCircularRegion(center: location, radius: radius, identifier: "SearchId")
        return region.contains(childLocation)
    }
    

提交回复
热议问题