Giter Club home page Giter Club logo

polyline's Introduction

Build Status CocoaPods Licence

Polyline encoder / decoder in Swift

  1. Features
  2. Requirements
  3. Integration
  4. Usage
  5. Notes
  6. Contributors
  7. License

Features

  • Encode a CLLocationCoordinate2D array to a polyline
  • Decode a polyline to an array of CLLocationCoordinate2D
  • Encode a CLLocation array to a polyline
  • Decode a polyline to an array of CLLocation
  • Encode/Decode associated levels (optional)
  • 100% Unit Test Coverage
  • Complete Documentation
  • Continuous integration with Travis CI
  • CocoaPod available
  • Convert to MKPolyline

Planned for future releases

  • Convert to GMSPolyline
  • Example project
  • Filter locations available at a specific level

Planned when support is available :

Requirements

  • Xcode 8+
  • iOS 8.0+ / Mac OS X 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Swift 3.0

Note: The last version to support Swift 2.3 is the 3.x series. 4.0 will only support Swift 3.x.


Integration

To use this library in your project you can use CocoaPods, Carthage, and/or integrate it manually :

CocoaPods

You can integrate Polyline in your Podfile like this:

pod 'Polyline', '~> 4.0'

Carthage

You can integrate Polyline in your Cartfile like this:

github "raphaelmor/Polyline" ~> 4.0

Manual

  • Drag Polyline.swift inside your project tree.
  • For Workspaces you may include the whole Polyline.xcodeproj

Usage

Polyline Encoding

Using [CLLocationCoordinate2D] (recommended) :

let coordinates = [CLLocationCoordinate2D(latitude: 40.2349727, longitude: -3.7707443),
CLLocationCoordinate2D(latitude: 44.3377999, longitude: 1.2112933)]

let polyline = Polyline(coordinates: coordinates)
let encodedPolyline: String = polyline.encodedPolyline

// Or for a functional approach :
let encodedPolyline: String = encodeCoordinates(coordinates)

Using [CLLocation] :

let locations = [CLLocation(latitude: 40.2349727, longitude: -3.7707443),
CLLocation(latitude: 44.3377999, longitude: 1.2112933)]

let polyline = Polyline(locations: locations)
let encodedPolyline: String = polyline.encodedPolyline

// Or for a functional approach :
let encodedPolyline: String = encodeLocations(locations)

You can encode levels too :

let levels: [UInt32] = [0,1,2,255]

let polyline = Polyline(coordinates: coordinates, levels: levels)
let encodedLevels: String? = polyline.encodedLevels

// Or for a functional approach :
let encodedLevels: String = encodedLevels(levels)

Polyline Decoding

You can decode to [CLLocationCoordinate2D] (recommended) :

let polyline = Polyline(encodedPolyline: "qkqtFbn_Vui`Xu`l]")
let decodedCoordinates: [CLLocationCoordinate2D]? = polyline.coordinates

// Or for a functional approach :
let coordinates: [CLLocationCoordinate2D]? = decodePolyline("qkqtFbn_Vui`Xu`l]")

You can also decode to [CLLocation] :

let polyline = Polyline(encodedPolyline: "qkqtFbn_Vui`Xu`l]")
let decodedLocations: [CLLocation]? = polyline.locations

// Or for a functional approach :
let locations: [CLLocation]? = decodePolyline("qkqtFbn_Vui`Xu`l]")

You can decode levels too :

let polyline = Polyline(encodedPolyline: "qkqtFbn_Vui`Xu`l]", encodedLevels: "BA")
let decodedLevels: [UInt32]? = polyline.levels

// Or for a functional approach :
let levels: [UInt32]? = decodeLevels("BA")

Polyline Precision

Default precision is 1e5 : 0.12345 (5 digit precision used by Google), but you can specify your own precision in all API methods (and functions).

// OSRM uses a 6 digit precision
let polyline = Polyline(encodedPolyline: "ak{hRak{hR", precision: 1e6)

Notes

This library tries to have consistent results with polylines generated by the Google Maps iOS SDK. The online tool for encoding polylines has some minor inconsistencies regarding rounding (for example, 0.000015 is rounded to 0.00002 for latitudes, but 0.00001 for longitudes).

This codes tries to adhere to the GitHub Swift Style Guide

Contributors

License

Polyline is released under an MIT license. See LICENSE.txt for more information.

polyline's People

Contributors

raphaelmor avatar tomtaylor avatar 1ec5 avatar orxelm avatar erichoracek avatar frederoni avatar gabrielcastro avatar tmcw avatar

Watchers

James Cloos avatar Alexis Jacquelin avatar

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.