seatcode / curvyRoute

iOS: Drawing curvy routes with MapKit

Home Page:https://medium.com/metropolis-lab/ios-drawing-curvy-routes-on-a-map-31f58dcc5159?source=friends_link&sk=8bf0d8b6a3e632c86b0842adbb110e8d

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PRs Welcome Version iOS 8.0+

๐Ÿ—บ curvyRoute

An easy way to draw a curvy line between two points on a map.

๐Ÿ† Features

  • Display a curve on a map
  • Display a straight line on a map
  • Customise the radius multiplier

๐Ÿ“ Requirements

  • iOS 8.0+
  • Swift 4.2+

๐Ÿ›  Installation

There are several methods to install curvyRoute:

CocoaPods

Add curvyRoute specs to your Podfile:

pod 'curvyRoute'

๐Ÿ‘‰๐Ÿผ Example

import MapKit
import UIKit
import curvyRoute

class ViewController: UIViewController, MKMapViewDelegate {
    @IBOutlet weak var mapView: MKMapView!

    override func viewDidAppear(_: Bool) {
        mapView.delegate = self
        addOverlays()
    }

    func mapView(_: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
        if let lineOverlay = overlay as? LineOverlay {
            return MapLineOverlayRenderer(lineOverlay)
        }
        return MKOverlayRenderer(overlay: overlay)
    }

    private func addOverlays() {
		let pointA = CLLocationCoordinate2DMake(41.375024, 2.149118) // Plaรงa d'Espanya, Barcelona
		let pointB = CLLocationCoordinate2DMake(41.380994, 2.185771) // Plaรงa Pau Vila, 1, Barcelona
        mapView.addOverlay(LineOverlay(origin: pointA, destination: pointB))
        let arc = ArcOverlay(origin: pointA, destination: pointB,
                             style: LineOverlayStyle(strokeColor: .systemTeal, lineWidth: 4, alpha: 1))
        arc.radiusMultiplier = 0.5
        mapView.addOverlay(arc)
    }
}

๐Ÿค” What is radiusMultiplier ?

This property will influence the shape of the arc. The default value is 1.

๐Ÿ‘จโ€๐Ÿ’ป Todo

  • Animate the polyline
  • ...

๐Ÿ“– License

curvyRoute is released under the MIT license. See LICENSE for details.