Skip to content

Instantly share code, notes, and snippets.

@raytiley
Created April 22, 2012 21:04
Show Gist options
  • Save raytiley/2466931 to your computer and use it in GitHub Desktop.
Save raytiley/2466931 to your computer and use it in GitHub Desktop.
Design Phase 4 - Routes Controller Example
// api/routes?start=300 main st boston&end=550 elm st boston&cost_table=popularity&route_type=cycle
app.get('api/routes', function(req,res){
//Parse Request for parameters
var start = req.params.start,
end = req.params.end,
costTable = req.params.cost_table,
routeType = req.params.route_type;
//Geocode Start and End
geoCoder.geocode([start,end], function(geoCodedResponse){
//Get Route from routingService
routingService.getRoute(geoCodedResponse[0].lat,
geoCodedResponse[0].lon,
geoCodedResponse[1].lat,
geoCodedResponse[1].lon,
routeType,
costTable,
function(route) {
//Send route as response to request
res.send(route);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment