How to know whether MKMapView visibleMapRect contains a Coordinate?

前端 未结 3 1951
情歌与酒
情歌与酒 2021-02-03 09:46

If I have a MKMapView and a CLLocationCoordinate2D how do you test whether the map\'s visible area contains the coordinate?

3条回答
  •  逝去的感伤
    2021-02-03 10:51

    my two cents for swift 5.1

      extension MKMapView {
    
          func contains(coordinate: CLLocationCoordinate2D) -> Bool {
            return self.visibleMapRect.contains(MKMapPoint(coordinate))
        }
    
     }
    

提交回复
热议问题