Was this helpful?

Adding Directions

A key part of an itinerary is to assist the user understand their movements. Alpaca offers services to assist providing information to users viewing your itineraries.

Alpaca can provide automatic routing to assist this process, of you can create your own directions to represent more complex directions and their representations. Various modes of transportation are supported to represent the movements of the traveller.

Alpaca supports a data structure to support manual data or automatic directions searching through a search service offered by Alpaca. You can also supply a single mode of transportation, or support mutli-modal transport.

Prerequisites

  • You'll need an itinerary you want to add to and locate the Itinerary ID

  • The itinerary will need to be unassigned to a profile, or you'll need your private API Key

Automatic Routing for added locations

You can get started with directions by leveraging the Automatic Routing capability that does not require you manually add directions. As you add locations to your itinerary, directions will be added automatically.

Adding a Car Route

The below example creates itinerary directions between two locations that are existing in your itinerary.

The single segment supplied is a Car segment, that is automatically searched for the best path to take.

1# Creates itinerary directions for between locations in an itinerary manually.
2# Can be used to create directions instead of using the Itinerary autoRoute
3# method or for where the itinerary is to contain multiple ways to move between
4# locations (alternative modes of transport between locations) or to provide
5# optional route options that may bypass specific locations in a sequence.
6
7mutation CreateItineraryDirections {
8  # use createItineraryDirections to create directions in an itinerary
9  createItineraryDirections(
10    # Supply the itinerary ID
11    itineraryId: "itinerary/ABC123"
12    # Provide the model for directions
13    directions: {
14      # Provide the route for the directions
15      route: {
16        segments: [
17          # Create segments for each mode. Add additional segments sequentially
18          # here as we support modal, e.g. Foot -> Car -> Foot etc. depending on
19          # the fidelity of the directions
20          {
21            # Indicate the mode of transport for this route segment
22            mode: Car
23            # Indicate whether we should search for this route
24            useRouteSearching: true
25          }
26        ]
27      }
28      # Contextualise the directions from origin/destination
29      # Origin itinerary location
30      originId: "itinerary/ABC123/item/startABC123"
31      # Position under the destination itinerary location
32      positionAtEnd: {
33        # Destination itinerary location
34        parentId: "itinerary/ABC123/item/endpointABC123"
35      }
36    }
37  ) {
38    # Query what was affected as a response
39    cascaded {
40      created {
41        id
42        __typename
43      }
44    }
45  }
46}

Sandbox: Configure | Try Operation

Adding a GPS Track (manual path)

You can also specify directions such as providing a manual track from GPS data.

Provide the GPS observations as the positions, and it is not necesarry to use useRouteSearching.

1# Creates itinerary directions for between locations in an itinerary by
2# supplying all the point information with a custom mode of transportation.
3
4mutation CreateItineraryDirectionsWithManualPositions {
5  # use createItineraryDirections to create directions in an itinerary
6  createItineraryDirections(
7    # Supply the itinerary ID
8    itineraryId: "itinerary/ABC123"
9    # Provide the model for directions
10    directions: {
11      # Provide the route for the directions
12      route: {
13        segments: [
14          # Add in a segment that is not using route searching and supplies
15          # the points
16          {
17            # Indicate the mode of transport for this route segment
18            mode: DogSled
19            # Provide the information for the segment
20            useRouteSearching: false
21            positions: [
22              # List the positions for the route
23              { lon: 24.235839843749996, lat: 60.600453043068256 }
24              { lon: 23.3184814453125, lat: 61.00507574751817 }
25              { lon: 24.532470703125, lat: 61.39145881217429 }
26              { lon: 25.784912109375, lat: 61.090168316050516 }
27              { lon: 25.323486328124996, lat: 60.63548951646859 }
28            ]
29          }
30        ]
31      }
32      # Contextualise the directions from origin/destination
33      # Origin itinerary location
34      originId: "itinerary/ABC123/item/startABC123"
35      # Position under the destination itinerary location
36      positionAtEnd: {
37        # Destination itinerary location
38        parentId: "itinerary/ABC123/item/endpointABC123"
39      }
40    }
41  ) {
42    # Query what was affected as a response
43    cascaded {
44      created {
45        id
46        __typename
47      }
48    }
49  }
50}

Sandbox: Configure | Try Operation

Showing directions to and from a location

When querying an itinerary location, you can query the corresponding directions for a given location.

1# Query an itinerary location and load the associated inbound or outbound
2# directions
3
4query QueryItineraryLocationDirections {
5  # Use the itineraryLocation operation
6  node(
7    # Supply the itinerary location ID
8    id: "itinerary/ABC123/item/DEF456"
9  ) {
10    ... on ItineraryLocation {
11      # Query the data you want for the itinerary location, such as
12      # content or information about the place
13      title
14      place {
15        address {
16          locality
17        }
18        maki
19        layers {
20          name
21        }
22      }
23      # Query any itinerary directions to or from this location
24      directions(first: 2) {
25        edges {
26          # Inbound or outbound direction
27          direction
28          node {
29            # Query the ItineraryDirection here
30            durationMin
31            distance
32            route {
33              segments {
34                mode
35              }
36            }
37          }
38        }
39      }
40    }
41  }
42}

Sandbox: Configure | Try Operation

Showing directions as part of an list of locations

When displaying a sequence of locations, such as a summary of the locations on an itinerary and the directions moving between these locations, you can use the edge data available between locations to query the connecting directions.

1# Query the itinerary locations, with information about the directions between
2# each of the locations
3
4query QueryItineraryLocationsWithDirections {
5  itinerary(
6    # Supply the itinerary ID
7    id: "itinerary/ABC123"
8  ) {
9    # Select the associated itinerary locations using the children selector
10    children(
11      # Limit to querying the itinerary locations
12      type: ItineraryLocation
13      # Using the relay "cursor connection" specification for pagination
14      # See: https://relay.dev/graphql/connections.htm
15      first: 10
16    ) {
17      edges {
18        node {
19          # ID/Types
20          id
21          __typename
22          # Specific information drawn from the Itinerary Location
23          ... on ItineraryLocation {
24            # Query the itinerary location
25            place {
26              # Peel off what information we want from to show about the place
27              name
28              # Take what level from the address we want
29              address {
30                locality
31              }
32              # Categories, like restaurant, hotel etc
33              layers {
34                name
35              }
36            }
37          }
38        }
39        # Additionally, query the routes between the locations as edge data,
40        # which will obtain directions from the itinerary that arrive (Inbound)
41        # to this location, from the last location in the edge sequence
42        directions(first: 1, direction: Inbound) {
43          nodes {
44            # Duration
45            durationMin
46            # Access the route modes (e.g. Car, etc)
47            route {
48              segments {
49                # Access polyline or geojson for each segment
50                mode
51              }
52            }
53            # Query any other ItineraryDirections data here..
54          }
55        }
56        # Obtain the cursor to pass back as the "after" property
57        cursor
58      }
59      # Total number of locations
60      totalCount
61    }
62  }
63}

Sandbox: Configure | Try Operation

alpaca.tech

Copyright © 2024 - Made with love ❤️ in Australia.