Get exact geo coordinates along an entire route, Google Maps or OpenStreetMap

It's simply google.maps.DirectionsService().route() method. You need to pass the service request and then a callback which executes upon completion of the service request.

https://developers.google.com/maps/documentation/javascript/directions


While not used as API, here: https://www.nmeagen.org/ one can create "Multi-point line", set the distance between points and download route (coordinates) as CSV.


Since the accepted answer is outdated and does not work anymore, here is how all nodes along a road can be queried using the route service from Project OSRM.

Given an arbitrary number of lon,lat pairs. For Instance the following three (in Berlin):

  • 13.388860,52.517037
  • 13.397634,52.529407
  • 13.428555,52.523219

The route-service calculates the fastest route between these points and its possible to return all nodes along the road using the following query:

http://router.project-osrm.org/route/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?alternatives=false&annotations=nodes

This returns a json response containing node IDs of all the nodes along the route. The result should look something like this:

{
  "routes": [
    {
      ...
      "legs": [
        {
          "annotation": {
            "nodes": [
              2264199819,
              2045820592,
              21487242,
              ...
    ]
 }

To receive the lat,lon coordinates of the nodes OverpassAPI can be used.

[out:json];
(
   node(264199819);
   node(...);
   node(...);
   ...
);
(._;>;);
out;

Here is a sample request using overpass-turbo: http://overpass-turbo.eu/s/toe


OSRM gives you routes with road geometries as they are in the OpenStreetMap database. For example, you can get the route as GPX (and post-process this file if you want). This would look like the following:

GET http://router.project-osrm.org/viaroute?hl=en&loc=47.064970,15.458470&loc=47.071100,15.476760&output=gpx

Read more: OSRM API docs.