Compute a route with Thinwrap (Go)

Compute a route via the Thinwrap Routing facade in Go — one call shape for Mapbox, Google, HERE, ESRI, TomTom and OSRM.

1. Install

go get github.com/thinwrap/location-go

2. Send the call

import "github.com/thinwrap/location-go"

r := location.NewRouting(location.MapboxConfig{
    AccessToken: os.Getenv("MAPBOX_ACCESS_TOKEN"),
})

res, err := r.Route(ctx, location.RoutingOptions{
    Waypoints: []location.LatLng{
        {Lat: 52.5200, Lng: 13.4050},
        {Lat: 52.5163, Lng: 13.3777},
    },
    TravelMode: location.Driving,
})
if err != nil {
    var ce *location.ConnectorError
    if errors.As(err, &ce) {
        log.Printf("%s: %s", ce.ProviderCode, ce.ProviderMessage)
    }
    return
}

// res.Polyline is the encoded geometry; res.Raw keeps the vendor body verbatim.
fmt.Println(res.TotalDistanceMeters, res.TotalDurationSeconds)

Same code works for all supported providers — just change the provider ID.