Search code examples
google-mapsroutesbing-mapsdirections

Live Map Directions while traveling


I'd like to create a route from point A to B.

I'd like to show the current position of the traveler on that route line.

If the traveler deviates from the route I'd like to update the route to compensate realtime.

Basically what Google maps does but I'd like this in my own application.

I looked at Google and Bing Maps API and nothing seems very intuitive.

Whats the best way of doing this?


Solution

  • Logic:

    Depending on what you're trying to achieve and most importantly, how you plan to implement those features, you might consider doing it in two steps.

    1/ Generate a basic route and create a buffer around

    To generate it, use the platform of your choice and retrieve the geometry that you will be able to use to generate

    2 / Detect if it get out of the original buffer and generate a new route and go back to step 1

    Once you get the buffer, your regularly (based on your location events for example) check the intersection with the buffered route, if it's out of the buffer, then you recreate the route and so on.

    Implementation:

    In order to do this, you might be interested in using Turf library, see this example:

    http://turfjs.org/examples/turf-buffer/

    Combined to Within() method:

    http://turfjs.org/examples/turf-within/

    Turf is available here: http://turfjs.org/

    Consideration

    Be careful though regarding the terms of use of each platforms as you might not do driving/navigation application depending on the cases and platforms you want to implement.

    You might be able to implement it quite easily, there might be something you can add to optimize accuracy (like bearing to the next geometry location, speed profile...), but I'm sure it will cover at least 90% of your needs based on the described case.