Class PolylineCodec
Google encoded-polyline (precision 5) decoder, the wire format OSRM and most routing APIs return geometry in.
public static class PolylineCodec
- Inheritance
-
objectPolylineCodec
Remarks
This is a wire boundary: the bytes come from a third-party server and may be corrupt or hostile. Three rules, in order. Nothing throws. Nothing moves a point, so no clamping, because a clamped coordinate is indistinguishable downstream from a real one. What cannot be represented rejects the whole geometry rather than half of it, because a route truncated at the bad point ends in the middle of nowhere with nothing to tell the caller it did. The antimeridian needs no special case: the format encodes differences between absolute coordinates, so a seam-crossing route written as 179.99 then -179.99 lands back in range on its own.
Methods
TryDecode(string, List<LatLon>)
Decodes an encoded polyline into WGS84 coordinates.
public static bool TryDecode(string encoded, List<LatLon> results)
Parameters
encodedstringEncoded polyline body. Null or empty decodes to nothing and succeeds.
resultsList<LatLon>Cleared first, then filled. Empty whenever this returns false.
Returns
- bool
True when the whole string decoded into coordinates LatLon accepts. False when any latitude leaves -90 to 90, any longitude leaves -180 to 180, or the string ends mid-varint.
Remarks
All or nothing, including for truncation. Deltas accumulate, so a coordinate can leave range with no single delta out of the ordinary: 19 successive +5 degree steps north do it.