Created
October 27, 2015 16:39
-
-
Save gustavompo/ca418df6c3402540d66c to your computer and use it in GitHub Desktop.
Routes for free
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "testing", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"express": "^4.13.3", | |
"request-promise": "^1.0.2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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