Instructions and Coordinates

Hi, my team is currently searching for Google Directions API alternatives and have recently come across GraphHopper. We need the turn instructions for our apps but is there a way to get the lat & long coordinates for each instruction for walking/foot? For example, if the user’s coordinate is near an instruction’s coordinate, that instruction sign will show up. We’re working on historic sites and parks so network connectivity is intermittent so we’re trying to find a way to match a user’s current coordinates to the coordinates of each instruction on the Instructions list. There is distance and time, but then it won’t be accurate if the user get’s off the path or takes too long to walk. Also tried points_encoded=false and api showed the lat long for the path, but how can we determing which lat long corresponds to which section of the instructions, just like the example at graphhopper.com ? Thank you for any help on this matter!

Yes, you can easily extract this information from the routing response. For every instruction in the list of instructions the response contains an interval field which contains the indices of the corresponding points:

{
  ...
  "paths": [
    {
      "distance": 1791.011,
      "weight": 307.852443,
      "time": 370962,
      "points": {
        "type": "LineString",
        "coordinates": [
          [
            11.539424,
            48.118352
          ],
      ...
      },
      "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": ""
        },
      ...
      ],
    ...
}

Quoting from the docs:

Two indices into points, referring to the beginning and the end of the segment of the route this instruction refers to.
Powered by Discourse