Show routing demonstration on radar page.
This commit is contained in:
parent
18c7a5f84b
commit
b4817546df
9 changed files with 392 additions and 129 deletions
27
tomtom/geojson.go
Normal file
27
tomtom/geojson.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package tomtom
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Convert a slice of points to GeoJSON
|
||||
func PolylineToGeoJSON(polyline []Point) string {
|
||||
var sb strings.Builder
|
||||
|
||||
sb.WriteString(`{"type":"LineString","coordinates":[`)
|
||||
|
||||
for i, point := range polyline {
|
||||
// IMPORTANT: GeoJSON uses [longitude, latitude] order!
|
||||
sb.WriteString(fmt.Sprintf("[%g,%g]", point.Longitude, point.Latitude))
|
||||
|
||||
// Add comma if not the last point
|
||||
if i < len(polyline)-1 {
|
||||
sb.WriteString(",")
|
||||
}
|
||||
}
|
||||
|
||||
sb.WriteString("]}")
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue