Was this helpful?

Automatic Routing between Locations

To assist with a common use case, you can leverage a basic feature known as automatic routing for your itinerary.

  • Add directions automatically between Locations

  • Can be enabled on existing itineraries (such as simple lists or favourites)

  • Supports making stops optional

  • Can use preferred entry positions for locations

  • Supports a wide range of direction modes, including Car, Foot, Bike, Hike etc

  • Can change the directions to use specific modes of transport, such as alternating between Car/Foot/etc.

  • Can customise to include waypoints or preferred directions

This feature when applied will assist creation of an itinerary by automatically creating directions between the sequence of locations as they are added to the itinerary.

Enabling automatic routing between locations

Directions contain information such as duration and distance estimates based, as well as providing map data for rendering.

There are a number of supported routing modes provided by Alpaca Travel that can be used to search for routes

  • Basic Profiles: Car, Foot, Bike, etc

  • Advanced Profiles: MountainBike, Hike, Bus, Motorcycle, Scooter, etc.

Prerequisites

  • GraphQL development environment (or GraphQL Playground)

  • Your API Key

1# Creates an itinerary, and configures it to assign automatic routes. Automatic
2# routes will assist basic itineraries by sequentially linking locations that
3# are added with directions, providing information about moving between these
4# locations.
5
6mutation CreateItineraryWithCarAutoRoute {
7  # When using the createItinerary mutation to create our itinerary
8  createItinerary(
9    itinerary: {
10      # Add our basic required fields
11      title: "Example Itinerary"
12      # Indicate the behaviour to auto route using Car as the default mode
13      autoRoute: { defaultMode: Car }
14    }
15  ) {
16    # Read back the created itinerary
17    itinerary {
18      # Access the Identifier, required for further query/mutations
19      id
20    }
21  }
22}

Sandbox: Configure | Try Operation

Enabling on an existing Itinerary

It can be possible to enable automatic routing on an existing itinerary by performing an mutation to update the itinerary.

1# Enable "auto-route" behaviour to an existing itinerary. Auto-route will assist
2# users create itineraries with directions automatically added between locations
3
4mutation UpdateItineraryAssignCarAutoRoute {
5  # Use the updateItinerary to modify an existing itinerary
6  updateItinerary(
7    # Supply the identifier of the itinerary
8    id: "itinerary/ABC123"
9    # Change the property of autoRoute to assign a default mode
10    itinerary: { autoRoute: { defaultMode: Car } }
11  ) {
12    # Read back information
13    itinerary {
14      id
15      autoRoute {
16        defaultMode
17      }
18    }
19  }
20}

Sandbox: Configure | Try Operation

Making locations "optional"

The Alpaca auto-route feature will create a sequence of ItineraryDirections between each of the ItineraryLocations that are added to an itinerary with this behaviour enabled.

In some use-cases, you may wish to not automatically route to a specific location, as it may be along the way between two locations, but not a mandatory stop for users.

Marking locations as optional to skip over in auto routing

1# Updates an itinerary location and marks the itinerary location as an optional
2# stop
3
4mutation UpdateItineraryLocationAsOptional {
5  # Use updateItineraryLocation mutation for making changes to ItineraryLocation
6  updateItineraryLocation(
7    # Supply your itinerary location that you wish to make optional
8    id: "itinerary/ABC123/item/DEF456"
9    # Supply the location fields changing
10    location: {
11      # Update the location to be marked as optional
12      optional: true
13    }
14  ) {
15    # Query back your location
16    location {
17      # Optional should now be true
18      optional
19    }
20    # Optionally see what else has been affected, such as a result of the
21    # autoroute behaviour updating new and existing ItineraryDirections when
22    # using this feature.
23    cascaded {
24      created {
25        id
26        __typename
27      }
28      updated {
29        id
30        __typename
31      }
32      deletedIds
33    }
34  }
35}

Sandbox: Configure | Try Operation

Modifying the itinerary direction

You can also switch the directions mode of transport for a specific section of your itinerary, such as switching from a car direction to a foot direction.

1# Updates an itinerary directions to switch the mode of transportation from one
2# mode (such as car) to an alterative mode, such as foot
3
4mutation UpdateItineraryDirectionMode {
5  # Use updateItineraryDirections operation to update directions
6  updateItineraryDirections(
7    # Provide the itinerary directions ID to update
8    id: "itinerary/ABC123/item/DEF456"
9    # Supply the directions
10    directions: {
11      # Modify the route with the directions
12      route: {
13        segments: [
14          # A single route segment..., you can use multiple.
15          {
16            # Indicate the mode of transport for this route segment
17            mode: Foot
18            # Provide the information for the segment
19            useRouteSearching: true
20            # Provide positions: [] here if you want to control the routing
21          }
22        ]
23      }
24    }
25  ) {
26    # Query what was affected as a response
27    cascaded {
28      updated {
29        id
30        __typename
31      }
32    }
33  }
34}

Sandbox: Configure | Try Operation

You can manage the created itinerary direction as a normal itinerary direction. As such, you can refer to the adding directions documentation

It is also possible to create more complex representations of a route, including directing the user to a point, and then switching the mode of transport to move the user to another point. This is known as "multi-modal" transportation and is supported by the Alpaca Travel platform.

Advanced: Assigning waypoints or alternative transport modes when adding locations

By default, directions are added using the default mode of the auto route feature, as well as navigating the user from the last location to the new added location.

This works for a majority of use cases, but in order to capture more real-world examples, Alpaca Travel offers a number of finer-grain specifications for automatic route behaviour, including:

  • Alternative GPS positions to navigate the user to, such as a preferred entrance locations, car-parks etc

  • Guiding the resulting searched route, by providing waypoints

  • Creating manual route paths, supply positions, duration, distances and disabling search behaviours

  • Switching the mode of transport used, deferring from the default mode of the itinerary

1# Adds a new location to an itinerary that has auto route enabled, and
2# customises the auto-route behaviour so that it uses an alternative mode of
3# transport when adding. There are further behaviours provided to extend
4# auto-routing, but further than this, you can leverage the
5# createItineraryDirections mutations that can support multi-modal transport,
6# GPS sequences or further
7
8mutation CreateItineraryLocationWithAutoRouteOptions {
9  # When creating an itinerary location
10  createItineraryLocation(
11    # Provide the itinerary to modify
12    itineraryId: "itinerary/ABC"
13
14    # Provide the location/place (dummy example)
15    location: {
16      # Describe the physical place
17      place: {
18        # See how to reference and add locations properly
19        position: { lon: 123, lat: 45 }
20      }
21      # Supply specific attributes to customise this location
22      attrs: [
23        # Provide an alternative position to directions navigating to this
24        # location such as sending the user to the entrace for the location, or
25        # alternative [lon,lat]
26        {
27          id: "itinerary/location/directions-position-preference"
28          value: [123, 45.6]
29        }
30      ]
31    }
32
33    # Modify the auto route behaviour when creating this location. Note: This
34    # is not a permanent change to the itinerary, and is instead modifying
35    # the resulting autoroute that would be created at the same time
36    autoRoute: {
37      mode: Foot
38      # Other options; positions, distance, duration, useRouteSearching...
39    }
40  ) {
41    cascaded {
42      # Read back what has been created when adding
43      created {
44        # Expecting ItineraryLocation and ItineraryDirections (auto route)
45        __typename
46        id
47      }
48    }
49  }
50}

Sandbox: Configure | Try Operation

alpaca.tech

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