tspsolver

Node adaptation of google-maps-tsp-solver (https://code.google.com/p/google-maps-tsp-solver/)

tspsolver

Server-side node module adaptation of google-maps-tsp-solver (https://code.google.com/p/google-maps-tsp-solver/). Uses googlemaps node module.

More information on how the original was implemented:

https://code.google.com/p/google-maps-tsp-solver/


var express = require('express');
var app = express();

app.get('/', function(req, res) { res.send("Use /route-optimizer") })

app.all('/route-optimizer', function(req, res) { var tsp = require('tspsolver');

if (req.method == "POST") {
    var addresses = req.body.address;
} else if (typeof req.query.address !== "undefined") {
    var addresses = req.query.address;
} else {
    res.send("No addresses specified!");
}

if (typeof addresses == "string") {
    var addressSingle = addresses;
    addresses = new Array();
    addresses.push(addressSingle);
}

for (var i=0;i<addresses.length;i++) {
    console.log("Adding address '"+addresses[i]+"'");
    tsp.addAddress(addresses[i]);
}

tsp.solveRoundTrip(function() {
    var embed_uri = tsp.createGoogleLink(true);
    var map_uri   = tsp.createGoogleLink();

    var send = {
        'addresses': addresses,
        'embed_uri': embed_uri,
        'map_uri' :  map_uri
    };

    console.log(send);
    res.send(send);
})

})

app.listen(3000);