I'm trying to have my MKCircle
fillColor
change when the markerType is different. For example, if the markerType
is "airport", then the fill should be red, and if it is "Sea Plane Base" then the fill should be black.
// MARK: Radius overlay
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKCircle {
let circle = MKCircleRenderer(overlay: overlay)
for markerType in airports {
if markerType.markerType == "airport" {
circle.strokeColor = UIColor.red
circle.fillColor = UIColor(red: 255, green: 0, blue: 0, alpha: 0.1)
circle.lineWidth = 1
} else {
circle.strokeColor = UIColor.black
circle.fillColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1)
circle.lineWidth = 1
}
}
return circle
} else {
return MKPolylineRenderer()
}
}
I'm using this function to show the radius.
func mainAirportRadius(radius: CLLocationDistance) {
//MARK: Airport location
for coordinate in airports {
let center = coordinate.coordinate
let circle = MKCircle(center: center, radius: radius)
mapView.add(circle)
}
}
Then I call it in the viewDidLoad
method
mainAirportRadius(radius: 8046.72)