Git Product home page Git Product logo

polyline-algorithm-csharp's Introduction

.NET Polyline Algorithm (.NET Standard 2.0)

Lightweight .NET Standard 2.0 library implementing Google Polyline Algorithm. Designed with respect to flexibility, but still with easy to use.

Getting started

Prerequisites

.NET Polyline Algorithm is avalable as nuget package Cloudikka.PolylineAlgorithm targeting .NET Standard 2.0.

Command line:

Install-Package Cloudikka.PolylineAlgorithm

NuGet Package Manager:

Cloudikka.PolylineAlgorithm

Warning

Library is using ValueTuple<T1,โ€‚T2> Structure. ValueTuple struct is avalable in .NET Framework 4.7 and above. Incase your project is targeting lower version of .NET Framework you probably have to install System.ValueTuple NuGet package. (not tested yet)

Command line:

Install-Package System.ValueTuple

NuGet Package Manager:

System.ValueTuple

Hot to use it

There are three ways how to use .NET Polyline Algorithm library based on your needs. For each is available Encode and Decode methods.

Static methods

Whenever you just need to encode or decode Google polyline you can use static methods defined in static PolylineAlgorithm class.

Decoding
	string polyline = "polyline";
	IEnumerable<(double, double)> coordinates = PolylineAlgorithm.Decode(polyline);
Encoding
	IEnumerable<(double, double)> coordinates = new (double, double) [] { (35.635, 76.27182), (35.2435, 75.625), ... };
	string polyline = PolylineAlgorithm.Encode(coordinates);

Default instance

If you need to use dependency injection, you would like to have instance to deliver the work for you. In that case you can use default instance of PolylineEncoding class, which implements IPolylineEncoding<(double Latitude, double Longitude)> interface.

Decoding
	string polyline = "polyline";
	var encoding = new PolylineEncoding();
	IEnumerable<(double, double)> coordinates = encoding.Decode(polyline);
Encoding
	IEnumerable<(double, double)> coordinates = new (double, double) [] { (35.635, 76.27182), (35.2435, 75.625), ... };
	var encoding = new PolylineEncoding();
	string polyline = encoding.Encode(coordinates);

Inherited base class

There may be a scenario you need to pass and return different types to and from without a need to add another extra layer. In this case you can inherit PolylineEncodingBase class and override template methods CreateResult and GetCoordinates.

Inheriting
	public class MyPolylineEncoding : PolylineEncodingBase<Coordinate> {
	
		protected override Coordinate CreateResult(double latitude, double longitude) {
				return new Coordinate(latitude, longitude);
		}
	
		protected override (double Latitude, double Longitude) GetCoordinate(Coordinate source) {
				return (source.Latitude, source.Longitude);
		}
		
	}
Decoding
	string polyline = "polyline";
	var encoding = new MyPolylineEncoding();
	IEnumerable<Coordinate> coordinates = encoding.Decode(polyline);
Encoding
	IEnumerable<Coordinate> coordinates = new Coordinate [] { new Coordinate(35.635, 76.27182), new Coordinate(35.2435, 75.625), ... };
	var encoding = new MyPolylineEncoding();
	string polyline = encoding.Encode(coordinates);

Documentation

Documentation is can be found at https://dropoutcoder.github.io/polyline-algorithm-csharp/api/index.html.

Happy coding!

polyline-algorithm-csharp's People

Contributors

dropoutcoder avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

polyline-algorithm-csharp's Issues

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.