PolylineAlgorithm 1.0.88.25
dotnet add package PolylineAlgorithm --version 1.0.88.25
NuGet\Install-Package PolylineAlgorithm -Version 1.0.88.25
<PackageReference Include="PolylineAlgorithm" Version="1.0.88.25" />
<PackageVersion Include="PolylineAlgorithm" Version="1.0.88.25" />
<PackageReference Include="PolylineAlgorithm" />
paket add PolylineAlgorithm --version 1.0.88.25
#r "nuget: PolylineAlgorithm, 1.0.88.25"
#:package PolylineAlgorithm@1.0.88.25
#addin nuget:?package=PolylineAlgorithm&version=1.0.88.25
#tool nuget:?package=PolylineAlgorithm&version=1.0.88.25
PolylineAlgorithm for .NET
Google's Encoded Polyline Algorithm compresses sequences of geographic coordinates into a compact ASCII string, widely used in mapping APIs. This library provides a fully compliant .NET implementation with extensible, type-safe encoding and decoding APIs.
Features
- Google-compliant polyline encoding/decoding for geographic coordinates
- Extensible APIs for custom coordinate and polyline types (
AbstractPolylineEncoder<TCoordinate, TPolyline>,AbstractPolylineDecoder<TPolyline, TCoordinate>) - Extension methods for encoding from
List<T>and arrays (PolylineEncoderExtensions) - Robust input validation and descriptive exceptions
- Configurable with
PolylineEncodingOptions(precision, buffer size, logging) - Thread-safe, stateless APIs
- Low-level utilities via static
PolylineEncodingclass (Normalize, Denormalize, TryReadValue, TryWriteValue, ValidateFormat, etc.) - Benchmarks and unit tests for correctness and performance
- Auto-generated API docs (API Reference)
- Supports .NET Core, .NET 5+, Xamarin, Unity, Blazor via
netstandard2.1
Installation
dotnet add package PolylineAlgorithm
or via NuGet PMC:
Install-Package PolylineAlgorithm
Quick Start
The library provides abstract base classes to build your own encoder and decoder for any coordinate and polyline type.
Implement a custom encoder
using PolylineAlgorithm;
using PolylineAlgorithm.Abstraction;
public sealed class MyPolylineEncoder : AbstractPolylineEncoder<(double Latitude, double Longitude), string> {
protected override double GetLatitude((double Latitude, double Longitude) coordinate) => coordinate.Latitude;
protected override double GetLongitude((double Latitude, double Longitude) coordinate) => coordinate.Longitude;
protected override string CreatePolyline(ReadOnlyMemory<char> polyline) => polyline.ToString();
}
Encode coordinates
using PolylineAlgorithm.Extensions;
var coordinates = new List<(double Latitude, double Longitude)>
{
(48.858370, 2.294481),
(51.500729, -0.124625)
};
var encoder = new MyPolylineEncoder();
string encoded = encoder.Encode(coordinates); // extension method for List<T>
Console.WriteLine(encoded);
// Output: "yseiHoc_MwacOjnwM"
Implement a custom decoder
using PolylineAlgorithm;
using PolylineAlgorithm.Abstraction;
public sealed class MyPolylineDecoder : AbstractPolylineDecoder<string, (double Latitude, double Longitude)> {
protected override (double Latitude, double Longitude) CreateCoordinate(double latitude, double longitude) => (latitude, longitude);
protected override ReadOnlyMemory<char> GetReadOnlyMemory(in string polyline) => polyline.AsMemory();
}
Decode polyline
string encoded = "yseiHoc_MwacOjnwM";
var decoder = new MyPolylineDecoder();
IEnumerable<(double Latitude, double Longitude)> decoded = decoder.Decode(encoded);
Advanced Usage
Use PolylineEncodingOptionsBuilder to customize precision, buffer size, and logging, then pass the built options to the encoder or decoder constructor:
using Microsoft.Extensions.Logging;
PolylineEncodingOptions options = PolylineEncodingOptionsBuilder.Create()
.WithPrecision(6) // 6 decimal places instead of the default 5
.WithStackAllocLimit(1024) // increase stack-alloc buffer
.WithLoggerFactory(loggerFactory) // plug in your ILoggerFactory
.Build();
var encoder = new MyPolylineEncoder(options);
var decoder = new MyPolylineDecoder(options);
Use static methods on PolylineEncoding for low-level normalization, validation, and bit-level read/write operations.
See API Reference for full documentation.
FAQ
- What coordinate ranges are valid?
Latitude: -90..90, Longitude: -180..180 (throwsArgumentOutOfRangeExceptionfor invalid input) - What happens if I pass malformed input to the decoder?
The decoder throwsInvalidPolylineExceptionwith a descriptive message. Wrap calls in a try/catch in your application. - What .NET versions are supported?
Any environment supportingnetstandard2.1 - How do I customize encoder options?
UsePolylineEncodingOptionsBuilderand pass the built options to the encoder or decoder constructor. - Where can I get help?
GitHub issues
Resources
- GitHub Repository — source code, issues, changelog, and samples
- API Reference — full auto-generated documentation
License
MIT License © Pete Sramek
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.0 && < 11.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.