Compute an isochrone with Thinwrap (Go)
Compute a travel-time or travel-distance polygon via the Thinwrap Isochrone facade in Go — one call shape for Mapbox, HERE and ESRI.
1. Install
go get github.com/thinwrap/location-go2. Send the call
import "github.com/thinwrap/location-go"
i := location.NewIsochrone(location.MapboxConfig{
AccessToken: os.Getenv("MAPBOX_ACCESS_TOKEN"),
})
res, err := i.Isochrone(ctx, location.IsochroneOptions{
Center: location.LatLng{Lat: 52.5200, Lng: 13.4050},
Type: location.IsochroneTime,
Values: []float64{300, 600}, // seconds
TravelMode: location.Driving,
})
if err != nil {
var ce *location.ConnectorError
if errors.As(err, &ce) {
log.Printf("%s: %s", ce.ProviderCode, ce.ProviderMessage)
}
return
}
// Each contour carries a GeoJSON Polygon ([lng, lat] rings).
for _, c := range res.Contours {
fmt.Println(len(c.Polygon.Coordinates))
}
Same code works for all supported providers — just change the provider ID.