openrouteservice-js – your JS library for spatial node applications!

And here comes another little Christmas present by HeiGIT: In addition to our previously released and highly appreciated python and R libraries we now offer an additional JavaScript API making the usage of the openrouteservice ecosystem covering the entire globe based on OpenStreetMap in your web applications terribly simple. From now on you will be able to consume the following services based on free and open data sources with a couple of lines of JS code:

  • directions for all different kinds of bicycle profiles, pedestrian, wheelchair, car and heavy vehicle
  • time-distance matrices
  • geocoding and reverse geocoding
  • isochrones for reachability applications
  • points of interest
  • elevation information for points and or linestrings

Here is a small example for a route request, could it be simpler?

const OrsDirections = require("./OrsDirections");

// add your api_key here
const Directions = new OrsDirections({
api_key: "XY"
});

Directions.calculate({
coordinates: [[8.690958, 49.404662], [8.687868, 49.390139]],
profile: "driving-car",
extra_info: ["waytype", "steepness"],
geometry_format: "encodedpolyline",
format: "json"
})
.then(function(json) {
console.log(JSON.stringify(json));
})
.catch(function(err) {
var str = "An error occured: " + err;
console.log(str);
});

Find the sources and further examples on GitHub/GIScience or simply install the library via node’s package manager npm.

Happy Coding and Merry Christmas!


Posted

in

,

by