如何在全球地图iOS Swift上向MKMapView添加覆盖

如何在全球地图iOS Swift上向MKMapView添加覆盖,ios,swift,mkmapview,mapkit,overlay,Ios,Swift,Mkmapview,Mapkit,Overlay,我正在尝试在整个地图空间中添加ovarlay。我试过使用 @可用(iOS 4.0,*)公共let MKMapRectWorld:MKMapRect 但我找不到正确的方法 我找到了一个办法 将覆盖添加到中的地图视图,例如viewDidLoad: if let fullRadius = CLLocationDistance(exactly: MKMapRectWorld.size.height) { mapView.add(MKCircle(center: mapVie

我正在尝试在整个地图空间中添加ovarlay。我试过使用
@可用(iOS 4.0,*)公共let MKMapRectWorld:MKMapRect
但我找不到正确的方法

我找到了一个办法

将覆盖添加到中的地图视图,例如viewDidLoad:

  if let fullRadius = CLLocationDistance(exactly: MKMapRectWorld.size.height) {

            mapView.add(MKCircle(center: mapView.centerCoordinate, radius: fullRadius))

        }
并实现委托方法:

 func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    if overlay.isKind(of: MKCircle.self) {

        let view = MKCircleRenderer(overlay: overlay)

        view.fillColor = UIColor.blue.withAlphaComponent(0.1)

        return view
    }
    return MKOverlayRenderer(overlay: overlay)
}
我找到了一条路

将覆盖添加到中的地图视图,例如viewDidLoad:

  if let fullRadius = CLLocationDistance(exactly: MKMapRectWorld.size.height) {

            mapView.add(MKCircle(center: mapView.centerCoordinate, radius: fullRadius))

        }
并实现委托方法:

 func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    if overlay.isKind(of: MKCircle.self) {

        let view = MKCircleRenderer(overlay: overlay)

        view.fillColor = UIColor.blue.withAlphaComponent(0.1)

        return view
    }
    return MKOverlayRenderer(overlay: overlay)
}