Piotr
Piotr

Reputation: 111

How to add overlay to MKMapView on the whole world map iOS Swift

I'm trying to add ovarlay on full map space. I tried use @available(iOS 4.0, *)public let MKMapRectWorld: MKMapRect but I can't find a correct way how to do it.

Upvotes: 2

Views: 1284

Answers (1)

Piotr
Piotr

Reputation: 111

I've found a way.

add overlay to map view in for exmple viewDidLoad:

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

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

        }

and implement delegate method:

 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)
}

Upvotes: 5

Related Questions