fix decoding encoreding

This commit is contained in:
2023-03-30 00:45:55 +02:00
parent 1442647132
commit 30339c9bdd
4 changed files with 227 additions and 5 deletions

View File

@@ -6,6 +6,62 @@ import (
"github.com/paulmach/orb"
)
// // Decode decodes coordinates to the "Encoded Polyline Algorithm Format"
// // More info: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
// // polyline: polyline string in "Encoded Polyline Algorithm Format"
// // precision: usually 5 or 6; Google's original algorithm uses 5 digits of decimal precision,
// // which is accurate to about a meter. A precision of 6 gives you an accuracy of about 10cm
// // more info: https://mapzen.com/blog/polyline-precision/
// func Decode(polyline string, precision uint32) orb.LineString {
// group := ""
// coordinates := []float64{}
// for _, letter := range polyline {
// group += string(letter)
// if (int32(letter)-63)&0x20 == 0 {
// coordinates = append(coordinates, decodeElement(group, precision))
// group = ""
// }
// }
// points := orb.LineString{}
// for i := 1; i < len(coordinates); i += 2 {
// points = append(points, orb.Point{round(coordinates[i], precision), round(coordinates[i-1], precision)})
// }
// for i := range points {
// if i > 0 {
// points[i][1] = round(points[i-1].Lat()+points[i].Lat(), precision)
// points[i][0] = round(points[i-1].Lon()+points[i].Lon(), precision)
// }
// }
// return points
// }
// // Decode5 is a short call for Decode with precision set to 5
// // Accuracy is about one meter
// func Decode5(polyline string) orb.LineString {
// return Decode(polyline, 5)
// }
// // Decode6 is a short call for Decode with precision set to 6
// // Accuracy is about ten centimeters
// func Decode6(polyline string) orb.LineString {
// return Decode(polyline, 6)
// }
// // decodeElement decodes an coordinate element (i.e. latitude or longitude)
// // from the "Encoded Polyline Algorithm Format"
// func decodeElement(group string, precision uint32) float64 {
// var c chunks
// c.ParseLine(group)
// return c.Coordinate(precision)
// }
func Decode(encoded *string, precisionOptional ...int) orb.LineString {
// default to 6 digits of precision
precision := 6