Skip to content

Calculate a route

Request

This POST endpoint accepts routing requests as JSON and returns the computed route as JSON. It offers a high degree of customization through the custom model to account for vehicle constraints such as height or weight, avoidance or exclusion of specific areas. It also provids rich route information including elevation data, turn-by-turn instructions, toll information, and other detailed path details.

Security
key
Bodyapplication/json
profilestring(VehicleProfileId)

The routing profile. It determines the network, speed and other physical attributes used when computing the route. The valid values are listed in Map Data and Routing Profiles.

Default:"car"
Example:"bike"
pointsArray of items

The query points used to calculate the route, requiring at least a start and a destination point, with optional via-points in between.

Example:
[ [ 11.539421, 48.118477 ], [ 11.559023, 48.12228 ] ]
point_hintsArray of strings

Optional parameter. Specifies a hint containing only the street name to better snap the coordinates (lon,lat) to the road network. For example, if an address or building has two or more neighboring streets, you can control which street is used to find the closest location.

Example:
[ "Lindenschmitstraße", "Thalkirchener Str." ]
snap_preventionsArray of strings

Optional parameter. Snapping is the process of finding the closest road location for GPS coordinates provided in the points array. The snap_preventions array allows you to prevent snapping to specific types of roads. For example, if the array includes bridge, then the routing engine will avoid snapping to a bridge, even if it is the closest road for the given point. Note that once snapped the routing algorithm can still route over bridges (or the other values). To avoid this you need to use the custom_model.

Items Enum:"motorway""trunk""bridge""ford""tunnel""ferry"
Example:
[ "motorway", "trunk", "bridge", "tunnel", "ferry", "ford" ]
curbsidesArray of strings

Optional parameter. It specifies on which side a point should be relative to the driver when she leaves/arrives at a start/target/via point. You need to specify this parameter for either none or all points. Only supported for motor vehicle profiles and OpenStreetMap.

Items Enum:"any""right""left"
Example:
[ "any", "right" ]
localestring

The locale of the resulting turn instructions. E.g. pt_PT for Portuguese or de for German.

Default:"en"
elevationboolean

If true, a third coordinate, the altitude, is included with all positions in the response. This changes the format of the points and snapped_waypoints fields of the response, in both their encodings. Unless you switch off the points_encoded parameter, you need special code on the client side that can handle three-dimensional coordinates.

Default:false
detailsArray of strings

Optional parameter. The following path details are available: street_name, street_ref, street_destination, leg_time, leg_distance, roundabout, country, time, distance, max_speed, max_weight, max_width, toll, road_class, road_class_link, road_access, road_environment, hazmat, hazmat_tunnel, hazmat_water, lanes, surface, smoothness, hike_rating, mtb_rating, foot_network, bike_network. The forum has examples for path details.

Example:
[ "road_class", "surface" ]
optimizestring

Normally, the calculated route will visit the points in the order you specified them. If you have more than two points, you can set this parameter to "true" and the points may be re-ordered to minimize the total travel time. Keep in mind that the limits on the number of locations of the Route Optimization API applies, and the request costs more credits.

Default:"false"
instructionsboolean

If instructions should be calculated and returned

Default:true
calc_pointsboolean

If the points for the route should be calculated at all.

Default:true
debugboolean

If true, the output will be formatted.

Default:false
points_encodedboolean

Allows changing the encoding of location data in the response. The default is polyline encoding, which is compact but requires special client code to unpack. (We provide it in our JavaScript client library!) Set this parameter to false to switch the encoding to simple coordinate pairs like [lon,lat], or [lon,lat,elevation].

Default:true
ch.disableboolean

Use true to enable the flexible mode to use the custom_model or any of the following options below.

Default:false
custom_modelobject(CustomModel)

The custom_model modifies the routing behaviour of the specified profile. The Custom Model guide describes it in detail. Below is a complete request example in Berlin that limits all speeds to 100km/h, excludes motorways and makes shorter routes a bit more likely than the default due to a higher distance_influence. Note that it also includes the "ch.disable": true parameter which is required to make use of custom_model.

{
  "points": [
    [
      13.31543,
      52.509535
    ],
    [
      13.29779,
      52.512434
    ]
  ],
  "profile": "car",
  "ch.disable": true,
  "custom_model": {
    "speed": [
      {
        "if": "true",
        "limit_to": "100"
      }
    ],
    "priority": [
      {
        "if": "road_class == MOTORWAY",
        "multiply_by": "0"
      }
    ],
    "distance_influence": 100
  }
} 
headingsArray of integers, (int32)

Favour a heading direction for a certain point. Specify either one heading for the start point or as many as there are points. In this case headings are associated by their order to the specific points. Headings are given as north based clockwise angle between 0 and 360 degree. This headings parameter also influences the tour generated with algorithm=round_trip and forces the initial direction. Requires ch.disable=true.

heading_penaltyinteger, (int32)

Time penalty in seconds for not obeying a specified heading. Requires ch.disable=true.

Default:300
pass_throughboolean

If true, u-turns are avoided at via-points with regard to the heading_penalty. Requires ch.disable=true.

Default:false
algorithmstring

Rather than looking for the shortest or fastest path, this parameter lets you solve two different problems related to routing: With alternative_route, we give you not one but several routes that are close to optimal, but not too similar to each other. Limitation: works with custom_model but not with custom profiles. With round_trip, the route will get you back to where you started. This is meant for fun (think of a bike trip), so we will add some randomness. The alternative_route.* and round_trip.* parameters control both features.

Enum:"round_trip""alternative_route"
round_trip.distanceinteger, (int32)

If algorithm=round_trip, this parameter configures approximative length of the resulting round trip.

Default:10000
round_trip.seedinteger, (int64)

If algorithm=round_trip, this sets the random seed. Change this to get a different tour for each value.

alternative_route.max_pathsinteger, (int32)

If algorithm=alternative_route, this parameter sets the number of maximum paths which should be calculated. Increasing can lead to worse alternatives.

Default:2
alternative_route.max_weight_factornumber

If algorithm=alternative_route, this parameter sets the factor by which the alternatives routes can be longer than the optimal route. Increasing can lead to worse alternatives.

Default:1.4
alternative_route.max_share_factornumber

If algorithm=alternative_route, this parameter specifies how similar an alternative route can be to the optimal route. Increasing can lead to worse alternatives.

Default:0.6
curl -i -X POST \
  'https://graphhopper.com/api/1/route?key=YOUR_API_KEY_HERE' \
  -H 'Content-Type: application/json' \
  -d '{
    "profile": "bike",
    "points": [
      [
        11.539421,
        48.118477
      ],
      [
        11.559023,
        48.12228
      ]
    ],
    "point_hints": [
      "Lindenschmitstraße",
      "Thalkirchener Str."
    ],
    "snap_preventions": [
      "motorway",
      "ferry",
      "tunnel"
    ],
    "details": [
      "road_class",
      "surface"
    ]
  }'

Responses

Routing Result

Headers
X-RateLimit-Limitinteger

Your current daily credit limit.

X-RateLimit-Remaininginteger

Your remaining credits until the reset. This value is measured before the current request's cost is deducted. Subtract X-RateLimit-Credits to get the balance after the request.

X-RateLimit-Resetinteger

The number of seconds that you have to wait before a reset of the credit count is done.

X-RateLimit-Creditsinteger

The credit costs for this request. Note it could be a decimal and even negative number, e.g. when an async request failed.

Bodyapplication/json
pathsArray of objects(RouteResponsePath)
infoobject(ResponseInfo)

Additional information for your request

Response
{ "hints": { "visited_nodes.sum": 58, "visited_nodes.average": 58 }, "info": { "copyrights": [ "GraphHopper", "OpenStreetMap contributors" ], "took": 2 }, "paths": [ { "distance": 1791.011, "weight": 307.852443, "time": 370962, "transfers": 0, "points_encoded": false, "bbox": [ 11.539424, 48.118343, 11.558901, 48.122364 ], "points": { "type": "LineString", "coordinates": [ [ 11.539424, 48.118352 ], [ 11.540387, 48.118368 ], [ 11.54061, 48.118356 ], [ 11.541941, 48.118409 ], [ 11.543696, 48.118344 ], [ 11.547167, 48.118343 ], [ 11.548478, 48.118366 ], [ 11.548487, 48.119329 ], [ 11.548807, 48.119328 ], [ 11.549408, 48.119366 ], [ 11.550349, 48.119508 ], [ 11.550441, 48.119473 ], [ 11.551109, 48.119467 ], [ 11.551553, 48.119445 ], [ 11.551748, 48.119398 ], [ 11.552087, 48.119475 ], [ 11.552236, 48.119542 ], [ 11.552353, 48.119635 ], [ 11.553853, 48.121136 ], [ 11.555448, 48.12039 ], [ 11.555797, 48.120206 ], [ 11.55632, 48.120592 ], [ 11.556716, 48.120919 ], [ 11.557326, 48.121345 ], [ 11.558901, 48.122364 ] ] }, "instructions": [ { "distance": 672.954, "heading": 89.04, "sign": 0, "interval": [ 0, 6 ], "text": "Continue onto Lindenschmitstraße", "time": 144703, "street_name": "Lindenschmitstraße" }, { "distance": 107.145, "sign": -2, "interval": [ 6, 7 ], "text": "Turn left", "time": 22675, "street_name": "" }, { "distance": 140.169, "sign": 2, "interval": [ 7, 10 ], "text": "Turn right onto Oberländerstraße", "time": 28032, "street_name": "Oberländerstraße" }, { "distance": 360.232, "sign": 1, "interval": [ 10, 18 ], "text": "Turn slight right", "time": 72677, "street_name": "" }, { "distance": 177.621, "sign": 2, "interval": [ 18, 20 ], "text": "Turn right onto Thalkirchner Straße", "time": 35524, "street_name": "Thalkirchner Straße" }, { "distance": 332.89, "sign": -2, "interval": [ 20, 24 ], "text": "Turn left onto Thalkirchner Straße", "time": 67351, "street_name": "Thalkirchner Straße" }, { "distance": 0, "sign": 4, "last_heading": 45.67046584987792, "interval": [ 24, 24 ], "text": "Arrive at destination", "time": 0, "street_name": "" } ], "legs": [], "details": {}, "ascend": 6.3294677734375, "descend": 25.0579833984375, "snapped_waypoints": { "type": "LineString", "coordinates": [ [ 11.539424, 48.118352 ], [ 11.558901, 48.122364 ] ] } } ] }