Calculates shortest path for given list of addresses. Server-side node.js module adaptation of google-maps-tsp-solver (https://code.google.com/p/google-maps-tsp-solver/). Uses googlemaps node module.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.jshintrc
.travis.yml
Gruntfile.js
LICENSE
README.md
index.js
package.json

README.md

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/

Example 1 - Round Trip using Express framework


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);