Post not yet marked as solved
Click to stop watching this thread.
You have stopped watching this post. Click to start watching again.
contentPostList.repliesup-voted.tooltip
Replied In
How to draw an arc in MKMapView?
I see this post is six years old...but...here's how I did it:
func addPolyLine(coordArray: [CLLocationCoordinate2D], count: Int, name: String){
let polyline = MKPolyline(coordinates: coordArray, count: count)
polyline.title = name
self.cruiseMap.delegate = self
self.cruiseMap.addOverlay(polyline)
}
func addSemiCircle(centerCoord: CLLocationCoordinate2D, r: Double, startBearing: Double, title: String){ // r in feet, bearings in degrees
var dots: [CLLocationCoordinate2D] = [N777.location, N777.location,N777.location,N777.location,N777.location,N777.location,N777.location,N777.location, N777.location,N777.location,N777.location,N777.location,N777.location]
// N777 is a structure, one of its variables is "location" which is a CLLocationCoordinate2D
let radianInc = 15*degreesToRadians
for dot in 0...12{
dots[dot] = locationWithBearing(bearing: startBearing*degreesToRadians + (Double(dot)*radianInc), distanceMeters: r*feetToMeters, origin: centerCoord)
}
addPolyLine(coordArray: dots, count: 13, name: title)
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if let polyline = overlay as? MKPolyline {
let lineRenderer = MKPolylineRenderer(polyline: polyline)
lineRenderer.alpha = 1.0
lineRenderer.strokeColor = polyLineColor
lineRenderer.lineWidth = polyLineWidth
return lineRenderer
}
return MKOverlayRenderer()
}