Skip to content

Instantly share code, notes, and snippets.

@gustavompo
Created October 27, 2015 16:39
Show Gist options
  • Save gustavompo/ca418df6c3402540d66c to your computer and use it in GitHub Desktop.
Save gustavompo/ca418df6c3402540d66c to your computer and use it in GitHub Desktop.
Routes for free
{
"name": "testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.13.3",
"request-promise": "^1.0.2"
}
}
var express = require('express'),
requestPromise = require('request-promise');
var app = express();
var services = {
mapquest: {
requestFor: function(oll, dll) {
return {
url: 'https://www.mapquestapi.com/directions/v2/route?key=Kmjtd|luua2qu7n9,7a=o5-lzbgq&json={"locations":["' + oll + '","' + dll + '"],"options":{"generalize":0}}',
headers: { 'Referer': 'https://developer.mapquest.com/documentation/javascript-api/routing' }
};
}
},
here: {
requestFor: function(oll, dll) {
return { url: 'https://route.cit.api.here.com/routing/7.2/calculateroute.json?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&mode=fastest;car&representation=display&routeattributes=waypoints,summary,shape,legs&maneuverattributes=direction,action&waypoint0=' + oll + '&waypoint1=' + dll };
}
},
mapbox: {
requestFor: function(oll, dll) {
return { url: 'https://api.tiles.mapbox.com/v4/directions/mapbox.driving/' + oll + ';' + dll + '.json?instructions=html&geometry=polyline&access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6IlhHVkZmaW8ifQ.hAMX5hSW-QnTeRCMAy9A8Q' };
}
},
};
app.get('/route', function(req, res) {
var routeSvcRequest = services[req.query.server].requestFor(req.query.origin, req.query.destination);
requestPromise(routeSvcRequest)
.then(function(data) {
res.set('Content-Type', 'text/javascript');
res.json(data);
res.end();
})
.catch(console.log);
});
app.listen(3000, function() { console.log("listening on port: 3000"); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment