This repository has been archived by the owner on Jun 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dane Springmeyer
committed
Feb 25, 2014
1 parent
ebd1691
commit dc1add7
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var express = require('express'); | ||
var osrm = require('../'); | ||
|
||
var app = express(); | ||
var use_shared_memory = true; | ||
var opts = new osrm.Options('test/data/berlin.ini', use_shared_memory); | ||
var engine = new osrm.Engine(opts); | ||
|
||
// Accepts a query like: | ||
// http://localhost:8888?start=52.519930,13.438640&end=52.513191,13.415852 | ||
app.get('/', function(req, res) { | ||
if (!req.query.start || !req.query.end) { | ||
return res.json({"error":"invalid start and end query"}); | ||
} | ||
var coordinates = []; | ||
var start = req.query.start.split(',') | ||
coordinates.push([+start[0],+start[1]]); | ||
var end = req.query.end.split(',') | ||
coordinates.push([+end[0],+end[1]]); | ||
var query = new osrm.Query({ | ||
coordinates: coordinates, | ||
alternateRoute: req.query.alternatives !== 'false' | ||
}); | ||
engine.run(query, function(err, result) { | ||
if (err) return res.json({"error":err.message}); | ||
try { | ||
return res.json(JSON.parse(result)); | ||
} catch (err) { | ||
return res.send(result); | ||
} | ||
}); | ||
}); | ||
|
||
console.log('Listening on port: ' + 8888); | ||
app.listen(8888); | ||
|