Documentation
¶
Overview ¶
Package polyline implements a Google Maps Encoding Polyline encoder and decoder.
See https://developers.google.com/maps/documentation/utilities/polylinealgorithm
The default codec encodes and decodes two-dimensional coordinates scaled by 1e5. For other dimensionalities and scales create a custom Codec.
Index ¶
- func DecodeCoord(buf []byte) ([]float64, []byte, error)
- func DecodeCoords(buf []byte) ([][]float64, []byte, error)
- func DecodeInt(buf []byte) (int, []byte, error)
- func DecodeUint(buf []byte) (uint, []byte, error)
- func EncodeCoord(coord []float64) []byte
- func EncodeCoords(coords [][]float64) []byte
- func EncodeInt(buf []byte, i int) []byte
- func EncodeUint(buf []byte, u uint) []byte
- type Codec
- func (c Codec) DecodeCoord(buf []byte) ([]float64, []byte, error)
- func (c Codec) DecodeCoords(buf []byte) ([][]float64, []byte, error)
- func (c Codec) DecodeFlatCoords(fcs []float64, buf []byte) ([]float64, []byte, error)
- func (c Codec) EncodeCoord(buf []byte, coord []float64) []byte
- func (c Codec) EncodeCoords(buf []byte, coords [][]float64) []byte
- func (c Codec) EncodeFlatCoords(buf []byte, fcs []float64) ([]byte, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeCoord ¶
DecodeCoord decodes a single coordinate from buf using the default codec.
func DecodeCoords ¶
DecodeCoords decodes an array of coordinates from buf using the default codec.
Example ¶
buf := []byte("_p~iF~ps|U_ulLnnqC_mqNvxq`@")
coords, _, _ := DecodeCoords(buf)
fmt.Printf("%v\n", coords)
Output: [[38.5 -120.2] [40.7 -120.95] [43.252 -126.453]]
func DecodeInt ¶
DecodeInt decodes a single signed integer from buf. It returns the decoded int, the remaining unconsumed bytes of buf, and any error.
func DecodeUint ¶
DecodeUint decodes a single unsigned integer from buf. It returns the decoded uint, the remaining unconsumed bytes of buf, and any error.
func EncodeCoord ¶
EncodeCoord returns the encoding of an array of coordinates using the default codec.
func EncodeCoords ¶
EncodeCoords returns the encoding of an array of coordinates using the default codec.
Example ¶
var coords = [][]float64{
{38.5, -120.2},
{40.7, -120.95},
{43.252, -126.453},
}
fmt.Printf("%s\n", EncodeCoords(coords))
Output: _p~iF~ps|U_ulLnnqC_mqNvxq`@
func EncodeUint ¶
EncodeUint appends the encoding of a single unsigned integer u to buf.
Types ¶
type Codec ¶
A Codec represents an encoder.
func (Codec) DecodeCoord ¶
DecodeCoord decodes a single coordinate from buf. It returns the coordinate, the remaining unconsumed bytes of buf, and any error.
func (Codec) DecodeCoords ¶
DecodeCoords decodes an array of coordinates from buf. It returns the coordinates, the remaining unconsumed bytes of buf, and any error.
func (Codec) DecodeFlatCoords ¶
DecodeFlatCoords decodes coordinates from buf, appending them to a one-dimensional array. It returns the coordinates, the remaining unconsumed bytes in buf, and any error.
func (Codec) EncodeCoord ¶
EncodeCoord encodes a single coordinate to buf.
func (Codec) EncodeCoords ¶
EncodeCoords appends the encoding of an array of coordinates coords to buf.