Search code examples
geolocation

How to Get Lattitude and Longitude of US Interstate Exits programmatically?


Is there a way to do that using open source map / API (Google Map API, Microsoft Live Map API)?

Or is there a way to traverse roads and junction from map files? (if I purchase commericial map data)

Thanks.

Edit: Either open source or API


Solution

  • A possible solution based on openstreetmap depending on the quality of OSM data in the US.

    As described here "Exit ramps/slip roads should be tagged as highway=motorway_link or highway=primary_link" if you import the map data for the US (using osm2pgsql) you can then select all motorway links.

    E.g. (selects based on my own data, i.e. very much outside US)

    openmapdb=# select osm_id, name, ref from planet_osm_roads where highway='motorway_link';
      osm_id  | name | ref 
    ----------+------+-----
     23683997 |      | 
     26436348 |      | 
     [..]
    

    23683997 and 26436348 are the OSM ids - if you click on the links you'll see they are indeed entry/exit ramps.

    Once you've identified a way, you can access the latitude and logitude:

    openmapdb=# select astext(st_transform(way, 4326)) from planet_osm_roads where osm_id = '23683997';                                                                                                                                             
        LINESTRING(24.8757131412186 44.8730730514894,[..]
    (1 row)