Giter Site home page Giter Site logo

seatcode / curvyroute Goto Github PK

View Code? Open in Web Editor NEW
40.0 6.0 6.0 515 KB

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

License: MIT License

Ruby 6.65% Swift 93.35%
mapkit ios ios-swift polyline route map

curvyroute's Introduction

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.

curvyroute's People

Contributors

zigzagg16 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

curvyroute's Issues

Question (Draggable Point at End of Line)

Hello! I need to have one end of the curved line be stationary that does not move then the other end be draggable by the user while keeping the curved line. What's the best way to do this? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.