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.
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.
The query points used to calculate the route, requiring at least a start and a destination point, with optional via-points in between.
[ [ 11.539421, 48.118477 ], [ 11.559023, 48.12228 ] ]
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.
[ "Lindenschmitstraße", "Thalkirchener Str." ]
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.
[ "motorway", "trunk", "bridge", "tunnel", "ferry", "ford" ]
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.
[ "any", "right" ]
The locale of the resulting turn instructions. E.g. pt_PT for Portuguese or de for German.
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.
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.
[ "road_class", "surface" ]
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.
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].
Use true to enable the flexible mode to use the custom_model or any of the following options below.
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
}
} 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.
Time penalty in seconds for not obeying a specified heading. Requires ch.disable=true.
If true, u-turns are avoided at via-points with regard to the heading_penalty. Requires ch.disable=true.
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.
If algorithm=round_trip, this parameter configures approximative length of the resulting round trip.
If algorithm=round_trip, this sets the random seed. Change this to get a different tour for each value.
If algorithm=alternative_route, this parameter sets the number of maximum paths which should be calculated. Increasing can lead to worse alternatives.
- https://graphhopper.com/api/1https://graphhopper.com/api/1/route
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"
]
}'{ "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 ] ] } } ] }