Skip to content
GuidesPlaygroundDashboard

Optimize route through waypoints

client.Optimize.New(ctx, body) (*OptimizeResult, error)
POST/api/v1/optimize

Optimize route through waypoints

ParametersExpand Collapse
body OptimizeNewParams
OptimizeRequest param.Field[OptimizeRequest]

Route optimization request through waypoints

ReturnsExpand Collapse
type OptimizeResult interface{…}

Optimization response — either a completed GeoJSON Feature route or an async job reference

One of the following:
type OptimizeCompletedResult struct{…}

Completed optimization — GeoJSON Feature with optimized route

Coordinates GeoJsonGeometryCoordinatesUnion

GeoJSON coordinates array (nesting depth varies by geometry type)

One of the following:
type GeoJsonGeometryCoordinatesArray []float64
type GeoJsonGeometryCoordinatesArray [][]float64
type GeoJsonGeometryCoordinatesArray [][][]float64
type GeoJsonGeometryCoordinatesArray [][][][]float64
Type GeoJsonGeometryType
One of the following:
const GeoJsonGeometryTypePoint GeoJsonGeometryType = "Point"
const GeoJsonGeometryTypeLineString GeoJsonGeometryType = "LineString"
const GeoJsonGeometryTypePolygon GeoJsonGeometryType = "Polygon"
const GeoJsonGeometryTypeMultiPoint GeoJsonGeometryType = "MultiPoint"
const GeoJsonGeometryTypeMultiLineString GeoJsonGeometryType = "MultiLineString"
const GeoJsonGeometryTypeMultiPolygon GeoJsonGeometryType = "MultiPolygon"
Properties OptimizeCompletedResultProperties
Distance float64optional

Total distance in meters

Duration float64optional

Estimated duration in seconds

WaypointOrder []int64optional

Optimized waypoint ordering

Status OptimizeCompletedResultStatus

Job status

Type OptimizeCompletedResultType
type OptimizeProcessingResult struct{…}

Async optimization in progress — poll with the job_id

JobID string

Job ID for polling

Status OptimizeProcessingResultStatus

Job status

Optimize route through waypoints

package main

import (
  "context"
  "fmt"

  "github.com/plazafyi/plaza-go"
  "github.com/plazafyi/plaza-go/option"
)

func main() {
  client := githubcomplazafyiplazago.NewClient(
    option.WithAPIKey("My API Key"),
  )
  optimizeResult, err := client.Optimize.New(context.TODO(), githubcomplazafyiplazago.OptimizeNewParams{
    OptimizeRequest: githubcomplazafyiplazago.OptimizeRequestParam{
      Waypoints: githubcomplazafyiplazago.F(githubcomplazafyiplazago.GeoJsonGeometryParam{
        Coordinates: githubcomplazafyiplazago.F[githubcomplazafyiplazago.GeoJsonGeometryCoordinatesUnionParam](githubcomplazafyiplazago.GeoJsonGeometryCoordinatesArrayParam([]float64{0.000000})),
        Type: githubcomplazafyiplazago.F(githubcomplazafyiplazago.GeoJsonGeometryTypePoint),
      }),
    },
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", optimizeResult)
}
Returns Examples