Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Suppose I have a route defined from one town to another. From the Google Maps API I can recover a route between the two. However, the route returned from Google is a driving route that includes geo-coordinates only at places where there is another step in a leg (for example, where I have to turn from one highway to another).

What I need is geo-locations (lat/long) along the entire route, at specific intervals (for example, every 1/4 mile or 100m).

Is there a way to accomplish this via the Google Maps API / web services?

Or would the OpenStreetMap database be the way to do it?

Kind regards, Madeleine.

like image 923
Madeleine P. Vincent Avatar asked May 23 '13 10:05

Madeleine P. Vincent


People also ask

Can you make Google Maps take a specific route?

You can add multiple stops along your route in Google Maps, up to a maximum of 10. Google will automatically plot a route. Then, to customize it, click and drag the destination line to the desired point. Your custom route will be saved to your Google Drive automatically.


2 Answers

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.

like image 191
tyr Avatar answered Oct 19 '22 21:10

tyr


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

like image 41
user2350644 Avatar answered Oct 19 '22 23:10

user2350644