Skip to content

Alternatives

Alternative Routes allows you to receive multiple route options for the same origin and destination points.


What are Alternative Routes?

The Alternative Routes feature calculates different route options for the same origin-destination pair. This allows you to:

  • Compare routes
  • Present options to the user
  • Evaluate alternatives based on traffic or other factors

Basic Usage

Set the alternatives field in the request body.

Field Type Required Default Allowed values Description
alternatives integer Optional 0 05 Number of alternative routes to request
curl -X POST "https://api.flio.ai/solver/route?api_key=YOUR-API-KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "origin": {
      "latitude": 41.0082,
      "longitude": 28.9784
    },
    "destination": {
      "latitude": 41.0150,
      "longitude": 28.9850
    },
    "alternatives": 2
  }'

The response is a top-level JSON array. Each returned route is an item in that array; there is no routes wrapper.


Configuration

Minimize Parameter

Use minimize to choose the calculation criterion applied to the primary route and its alternatives.

Value Description
duration Prioritizes routes with shorter travel time
distance Prioritizes routes with shorter travel distance

Combination with Avoid Features

The alternatives field requests additional route options. The minimize and avoid_features fields control how those routes are calculated; they are not alternative-route mechanisms by themselves.

{
  "origin": {
    "latitude": 41.0082,
    "longitude": 28.9784
  },
  "destination": {
    "latitude": 41.015,
    "longitude": 28.985
  },
  "alternatives": 2,
  "minimize": "duration",
  "avoid_features": ["tollRoad"]
}

Sending separate requests with different minimize or avoid_features values compares different calculation criteria. It does not use the Alternatives feature.


Use Cases

1. Route Comparison

Present different route options to users.

2. Cost Analysis

Compare the costs of returned routes.

3. Contingency Planning

Prepare alternatives for the primary route.


Python Example

import requests

API_BASE_URL = "https://api.flio.ai"
API_KEY = "YOUR-API-KEY"


def get_alternatives(origin, destination, count=2):
    response = requests.post(
        f"{API_BASE_URL}/solver/route?api_key={API_KEY}",
        json={
            "origin": origin,
            "destination": destination,
            "alternatives": count,
        },
    )
    response.raise_for_status()
    return response.json()


origin = {"latitude": 41.0082, "longitude": 28.9784}
destination = {"latitude": 41.0150, "longitude": 28.9850}

routes = get_alternatives(origin, destination)
for index, route in enumerate(routes, start=1):
    summary = route["summary"]
    print(
        f"Route {index}: "
        f"{summary['distance']}m, {summary['duration']}s"
    )

Alternative Routes — Flio.ai

Next Steps