Help to understand /v2/directions/{profile} post response

Hi,

I used below API

  curl -X POST \
  'https://api.openrouteservice.org/v2/directions/driving-car' \
  -H 'Content-Type: application/json; charset=utf-8' \
  -H 'Accept: application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8' \
  -H 'Authorization: 5*******283e' \
  -d '{"coordinates":[[8.681495,49.41461],[8.686507,49.41943],[8.687872,49.420318]]}'

Response I got is

{
    "bbox": [
        8.681423,
        49.414599,
        8.690123,
        49.420514
    ],
    "routes": [
        {
            "summary": {
                "distance": 1372.6,
                "duration": 292.79999999999995
            },
            "segments": [
                {
                    "distance": 891.1,
                    "duration": 189.7,
                    "steps": [
                        {
                            "distance": 1.8,
                            "duration": 0.4,
                            "type": 11,
                            "instruction": "Head west on Gerhart-Hauptmann-Straße",
                            "name": "Gerhart-Hauptmann-Straße",
                            "way_points": [
                                0,
                                1
                            ]
                        },
                        {
                            "distance": 313.8,
                            "duration": 75.3,
                            "type": 1,
                            "instruction": "Turn right onto Wielandtstraße",
                            "name": "Wielandtstraße",
                            "way_points": [
                                1,
                                6
                            ]
                        },
                        {
                            "distance": 251.7,
                            "duration": 36.2,
                            "type": 1,
                            "instruction": "Turn right onto Mönchhofstraße",
                            "name": "Mönchhofstraße",
                            "way_points": [
                                6,
                                10
                            ]
                        },
                        {
                            "distance": 211.8,
                            "duration": 50.8,
                            "type": 0,
                            "instruction": "Turn left onto Keplerstraße",
                            "name": "Keplerstraße",
                            "way_points": [
                                10,
                                13
                            ]
                        },
                        {
                            "distance": 109.5,
                            "duration": 26.3,
                            "type": 1,
                            "instruction": "Turn right onto Moltkestraße",
                            "name": "Moltkestraße",
                            "way_points": [
                                13,
                                14
                            ]
                        },
                        {
                            "distance": 2.4,
                            "duration": 0.6,
                            "type": 0,
                            "instruction": "Turn left onto Werderplatz",
                            "name": "Werderplatz",
                            "way_points": [
                                14,
                                15
                            ]
                        },
                        {
                            "distance": 0,
                            "duration": 0,
                            "type": 10,
                            "instruction": "Arrive at Werderplatz, on the right",
                            "name": "-",
                            "way_points": [
                                15,
                                15
                            ]
                        }
                    ]
                },
                {
                    "distance": 481.5,
                    "duration": 103.1,
                    "steps": [
                        {
                            "distance": 2.4,
                            "duration": 0.6,
                            "type": 11,
                            "instruction": "Head south on Werderplatz",
                            "name": "Werderplatz",
                            "way_points": [
                                15,
                                16
                            ]
                        },
                        {
                            "distance": 265.5,
                            "duration": 63.7,
                            "type": 0,
                            "instruction": "Turn left onto Moltkestraße",
                            "name": "Moltkestraße",
                            "way_points": [
                                16,
                                20
                            ]
                        },
                        {
                            "distance": 83,
                            "duration": 7.5,
                            "type": 2,
                            "instruction": "Turn sharp left onto Handschuhsheimer Landstraße, B 3",
                            "name": "Handschuhsheimer Landstraße, B 3",
                            "way_points": [
                                20,
                                22
                            ]
                        },
                        {
                            "distance": 130.6,
                            "duration": 31.4,
                            "type": 0,
                            "instruction": "Turn left onto Roonstraße",
                            "name": "Roonstraße",
                            "way_points": [
                                22,
                                23
                            ]
                        },
                        {
                            "distance": 0,
                            "duration": 0,
                            "type": 10,
                            "instruction": "Arrive at Roonstraße, straight ahead",
                            "name": "-",
                            "way_points": [
                                23,
                                23
                            ]
                        }
                    ]
                }
            ],
            "bbox": [
                8.681423,
                49.414599,
                8.690123,
                49.420514
            ],
            "geometry": "ghrlHir~s@?BIC{ELgDo@aBa@}@I?sB?k@BwD?_JgAJgHt@I@]iHC?B?KuB]oFASg@wImAt@y@f@d@bJ",
            "way_points": [
                0,
                15,
                23
            ],
            "legs": []
        }
    ],
    "metadata": {
        "attribution": "openrouteservice.org | OpenStreetMap contributors",
        "service": "routing",
        "timestamp": 1690487824223,
        "query": {
            "coordinates": [
                [
                    8.681495,
                    49.41461
                ],
                [
                    8.686507,
                    49.41943
                ],
                [
                    8.687872,
                    49.420318
                ]
            ],
            "profile": "driving-car",
            "format": "json"
        },
        "engine": {
            "version": "7.1.0",
            "build_date": "2023-07-09T01:31:50Z",
            "graph_date": "2023-07-23T10:09:25Z"
        }
    }
}

But How to draw a line string(route) on the map. In the playground, it is showing that in a red line.

And also I did not understand what is this value means

"geometry": "ghrlHir~s@?BIC{ELgDo@aBa@}@I?sB?k@BwD?_JgAJgHt@I@]iHC?B?KuB]oFASg@wImAt@y@f@d@bJ"

Thank you I got my answer.

1 Like

Thanks for following-up on this with your solution. Appreciate that!

If you would rather not deal with encoded geometries, try to query the GeoJSON endpoints directly:

# As described here: https://openrouteservice.org/dev/#/api-docs/v2/directions/%7Bprofile%7D/geojson/post
 
  curl -X POST \
  'https://api.openrouteservice.org/v2/directions/driving-car/geojson' \
  -H 'Content-Type: application/json; charset=utf-8' \
  -H 'Accept: application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8' \
  -H 'Authorization: your-api-key' \
  -d '{"coordinates":[[8.681495,49.41461],[8.686507,49.41943],[8.687872,49.420318]]}'

If you need any further information, just let us know.