How to use the Route Directions API

Route Directions API example showing a multi-stop driving route on a map
Route Directions API example showing a multi-stop driving route on a map

This tutorial shows how to use the Route Directions (Routing) API in practice: how to build requests, choose route parameters, and read response details for real routing scenarios.

Start here:

There are many use cases for the Route Directions API. Here are a few examples:

Quick Start

If you want to test the API quickly, use this request:

https://api.geoapify.com/v1/routing?waypoints=37.7790262,-122.419906|36.190364,-115.279104&mode=drive&details=route_details&apiKey=YOUR_API_KEY

Replace YOUR_API_KEY with your key from Get Started with Maps API. You can also test requests first in the Routing API Playground.

In the response, check these fields first:

  • features[0].geometry for the route line
  • features[0].properties.distance and features[0].properties.time for route summary
  • features[0].properties.legs for segment-level details

Route Directions API Parameters

Use these parameters to control how routes are calculated and what extra data is returned. For the full specification and all supported options, see the Routing API documentation.

ParameterWhat it controlsCommon valuesDefaultExample
waypointsRoute start/end (and optional intermediate stops). Format: lat,lon|lat,lon...Any valid coordinate pairsRequiredwaypoints=37.7790262,-122.419906|36.190364,-115.279104
modeTransportation profiledrive, truck, walk, bike, transitdrivemode=drive
typeRoute optimization strategybalanced, short, less_maneuversbalancedtype=balanced
avoidRoad/area constraintshighways, tolls, ferries, location:lat,lon (can combine with |)noneavoid=highways|tolls|location:40.884414,-73.947588
detailsAdditional response sectionsinstruction_details, route_details, elevationnonedetails=instruction_details
trafficTraffic model for motorized modesfree_flow, approximatedfree_flowtraffic=approximated
unitsDistance/time units in responsemetric, imperialmetricunits=imperial
langLocalized instruction/output languageen, de, es, fr, it, pt, ...enlang=de

Now let's look at each parameter in more detail.

waypoints Parameter

Use waypoints to define the route points in order.
Format: lat,lon|lat,lon|... (start -> intermediate stops -> destination).

For example, let's say you want to find the best route between Los Angeles and San Francisco. You would specify the following waypoints:

waypoints=34.0428494,-118.2476732|37.7790262,-122.419906

Request example (two waypoints):

https://api.geoapify.com/v1/routing?waypoints=34.0428494,-118.2476732|37.7790262,-122.419906&mode=drive&apiKey=YOUR_API_KEY
Route between Los Angeles and San Francisco (two waypoints)

You can add intermediate stops. For example, route through Los Angeles -> San Francisco -> Las Vegas:

waypoints=34.0428494,-118.2476732|37.7790262,-122.419906|36.190364,-115.279104

Request example (three waypoints):

https://api.geoapify.com/v1/routing?waypoints=34.0428494,-118.2476732|37.7790262,-122.419906|36.190364,-115.279104&mode=drive&apiKey=YOUR_API_KEY
Route between Los Angeles, San Francisco, and Las Vegas (three waypoints)

mode Parameter

Use mode to choose the transportation profile, such as drive, bike, walk, or transit.

Request example (mode=drive):

https://api.geoapify.com/v1/routing?waypoints=37.7790262,-122.419906|36.190364,-115.279104&mode=drive&apiKey=YOUR_API_KEY
Route where the mode parameter is set to drive

type Parameter

The type parameter is used to specify the type of route to calculate. The possible values are short, balanced, and less_maneuvers. The default value is balanced.

Use type=balanced for a practical balance between travel time, distance, and maneuver complexity.

Use type=short when you want the shortest route by distance (not always the fastest by time).

Use type=less_maneuvers to reduce turns and maneuver-heavy paths.

Example with two mountainous locations (Denver -> Idaho Springs) and type=balanced:

https://api.geoapify.com/v1/routing?waypoints=39.7392364,-104.984862|39.7425969,-105.5136365&mode=drive&type=balanced&apiKey=YOUR_API_KEY
Route between Denver and Idaho Springs, where the type property is set to balanced

With type=short, the API prefers the shortest route by length:

https://api.geoapify.com/v1/routing?waypoints=39.7392364,-104.984862|39.7425969,-105.5136365&mode=drive&type=short&apiKey=YOUR_API_KEY
Route between Denver and Idaho Springs, where the type property is set to short

avoid Parameter

Use avoid to exclude specific road types or locations from route calculation.
Common values are highways, tolls, ferries, and location:lat,lon. Default is none.

If you want to avoid highways, set avoid=highways.

Request example (avoid=highways):

https://api.geoapify.com/v1/routing?waypoints=40.9912087,-74.0326395|40.748428399999995,-73.98565461987332&mode=drive&avoid=highways&apiKey=YOUR_API_KEY
Route without the avoid parameter set

You can also avoid a specific point by coordinates using avoid=location:lat,lon.

For example, to avoid Englewood Cliffs (40.884414,-73.947588), use avoid=location:40.884414,-73.947588.

https://api.geoapify.com/v1/routing?waypoints=40.9912087,-74.0326395|40.748428399999995,-73.98565461987332&mode=drive&avoid=highways|location:40.884414,-73.947588&apiKey=YOUR_API_KEY
Route with the avoid parameter set

details Parameter

Use details to include additional route data in the response.

Possible values are instruction_details,route_details and elevation. The default value is none, which means that no additional information will be included in the response.

details=instruction_details adds turn-by-turn instructions for each step.

For more advanced guidance on combining turn-by-turn instructions with static maps to create printable driving directions, see our tutorial on printable driving directions.

Request example (details=instruction_details):

https://api.geoapify.com/v1/routing?waypoints=37.7790262,-122.419906|36.190364,-115.279104&mode=drive&details=instruction_details&apiKey=YOUR_API_KEY

The returned GeoJSON includes extra instruction data per step.

Returned GeoJSON object including route instructions

details=route_details adds route-level metadata such as travel time and distance.

Request example (details=route_details):

https://api.geoapify.com/v1/routing?waypoints=37.7790262,-122.419906|36.190364,-115.279104&mode=drive&details=route_details&apiKey=YOUR_API_KEY

The returned GeoJSON object will include route-level metadata such as distance and travel time.

Returned GeoJSON object including route information

details=elevation adds elevation data for the route profile.

Request example (details=elevation):

https://api.geoapify.com/v1/routing?waypoints=37.7790262,-122.419906|36.190364,-115.279104&mode=drive&details=elevation&apiKey=YOUR_API_KEY
Route including elevation information

traffic Parameter

Use traffic to control how traffic conditions influence route estimation for motorized modes (drive, truck, etc.). free_flow (default) assumes optimistic traffic, while approximated applies congestion-aware speed reductions.

In practice, approximated may select a longer route if its estimated travel time is lower under traffic. Below we compare routes for San Francisco -> Las Vegas with both traffic models.

free_flow

https://api.geoapify.com/v1/routing?waypoints=37.7790262,-122.419906|36.190364,-115.279104&mode=drive&traffic=free_flow&apiKey=YOUR_API_KEY
Route where the traffic property is set to free_flow

approximated

https://api.geoapify.com/v1/routing?waypoints=37.7790262,-122.419906|36.190364,-115.279104&mode=drive&traffic=approximated&apiKey=YOUR_API_KEY
Route where the traffic property is set to approximated

As shown above, approximated can prefer a longer route when congestion makes it faster overall.

units Parameter

The units parameter specifies the units that should be used for distance and time values. The default value is metric, which uses meters. You can also specify imperial, which uses miles.

Request example (units=imperial):

https://api.geoapify.com/v1/routing?waypoints=37.7790262,-122.419906|36.190364,-115.279104&mode=drive&units=imperial&apiKey=YOUR_API_KEY

lang Parameter

Use lang to localize display values and turn-by-turn instructions in the response.

The possible values for this parameter are en (English), de (German), es (Spanish), fr (French), it (Italian), pt (Portuguese) and many others. The default value is en.

Request example (lang=de):

https://api.geoapify.com/v1/routing?waypoints=37.7790262,-122.419906|36.190364,-115.279104&mode=drive&lang=de&details=instruction_details&apiKey=YOUR_API_KEY
API output when the lang parameter is set to DE

Troubleshooting

If a route result looks wrong, start with a minimal request (waypoints, mode, apiKey) and then add one parameter at a time.

IssueLikely causeHow to fix
Locations are in unconnected regions. Please check waypoint coordinate order (lat/lon).lat/lon swapped or points placed in disconnected areasConfirm every waypoint is lat,lon (not lon,lat) and recheck coordinates on the map
Unexpected route choiceavoid, traffic, or type parameters are biasing resultsRemove these parameters, then re-add one by one and compare distance and time
Travel time seems too optimisticDefault traffic=free_flow ignores congestionUse traffic=approximated
Missing instructions or summary fieldsRequired details option not requestedAdd details=instruction_details and/or details=route_details
Wrong language in instructionslang missing or instructions details not requestedSet lang (for example, de) and include details=instruction_details
Too many requests (HTTP 429)Request bursts exceed rate limitsAdd client-side rate limiting, queue requests, and retry with backoff
Auth errors (401/403)Invalid/missing API key or insufficient accessConfirm apiKey is present, valid, and enabled for routing

Learn More

Explore related Routing API resources to deepen implementation and integration. These guides cover route visualization, elevation profiles, printable directions, and production API usage.

Visualize a route on a MapLibre GL (Mapbox GL) map

How to draw routes on a Maplibre GL (Mapbox GL) map

Learn how to draw the route created by the API on a Maplibre GL (Mapbox GL) map. Check out our live demo on JSFiddle.
Grand Loop Road, Yellowstone National Park elevation profile

Drawing Route Elevation Profile with Chart.js

Learn how to draw road elevations on a chart with chart.js library. Get started quickly with our JSFiddle code sample.
Working on a JSFiddle example demonstrating how to generate printable map directions, integrating route visualization and step-by-step navigation

How to Create Printable Driving Directions with Geoapify

Learn how to create printable driving directions using the Geoapify Routing API and Static Map API.

FAQ

What is the difference between type=balanced and type=short?

balanced aims for a practical balance between travel time and route quality, while short prioritizes shortest distance. The shortest route is not always the fastest route.

How do I avoid toll roads or highways?

Use the avoid parameter. Example: avoid=highways|tolls. You can also avoid a specific point with avoid=location:lat,lon.

How do I get turn-by-turn instructions?

Set details=instruction_details. The response will include step-level instruction data you can use for navigation UI.

How do I include route summary data like time and distance?

Set details=route_details. This adds route-level metadata such as travel time and distance.

How can I test the Routing API before integration?

Use the Routing API Playground for quick tests, then integrate with your key from Get Started with Maps API.

Where can I find full Routing API documentation?

See the official Routing API Documentation for full parameter details and examples.