Google Maps Big Route Optimizer: Get optimized routes between many locations

Recommend this page to a friend!
     
  Info   Example   View files Files   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 193 All time: 260 This week: 3Up
Version License JavaScript version Categories
gmaps-routeoptimizer 1.0GNU General Publi...1.8Geography, Algorithms
Description 

Author

This object can get optimized routes between many locations.

It takes a distance matrix between given locations obtained using Google Maps API using the Google Maps Big Distance Matrix and computes the shortest route to travel to the locations.

This object implements the Ant Colony Algorithm to get the shortest path using distance, time or speed (distance/time) as optimization variables.

It can display the optimal route on a HTML div or export it as an array in JSON format.

Innovation Award
JavaScript Programming Innovation award winner
August 2014
Winner
When it is necessary to travel between many locations, routing optimization algorithms help reducing traveling costs by find optimal paths.

This object implements a route optimization solution using the Ant colony algorithm.

Manuel Lemos
Picture of David Castillo
  Performance   Level  
Name: David Castillo <contact>
Classes: 2 packages by
Country: Mexico Mexico
Age: 37
All time rank: 984 in Mexico Mexico
Week rank: 6 Up1 in Mexico Mexico Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Example

/* //Cities var Route_Points = { "Monterrey, MX": [25.6667, -100.3000], "Mexico City, MX": [19.4333, -99.1333], "Veracruz, MX": [19.1903, -96.1533], "Guadalajara, MX": [20.6667, -103.3500], "Tijuana, MX": [32.5250, -117.0333], "Acapulco, MX": [16.8636, -99.8825], "Cancun, MX": [21.1606, -86.8475] }; */ // Places in NY. var Route_Points = { "Times Square": [40.758673, -73.985281], "St Patrick's Cathedral": [40.758196, -73.975347], "Grand Central Terminal": [40.752105, -73.977686], "New York Public Library": [40.752617, -73.982793], "Washington Park, NJ": [40.751890, -74.041414], "Battery Park": [40.704506, -74.014206], "Liberty State Park": [40.708865, -74.042745], "Radio City Music Hall": [40.759770, -73.980134], "Grand Army Plaza": [40.763742, -73.973689], "Metropolitan Museum of Art": [40.778437, -73.962668], "Museum of Natural History": [40.780736, -73.972635], "Madison Square Garden": [40.749524, -73.993016], "United Nations Headquarters": [40.748807, -73.968089], "Bellevue Hospital Center": [40.738496, -73.976469], "New York City Hall": [40.712672, -74.006134], "9/11 Memorial and Museum": [40.711583, -74.012196], "Newport Green Park": [40.731766, -74.034086], "Yankee Stadium": [40.829271, -73.928536], "Federal Reserve": [40.708372, -74.008390], "Woolworth Building": [40.712190, -74.008505], "Brooklyn Botanic Garden": [40.666095, -73.961542], "JFK Airport": [40.646113, -73.783744], "LaGuardia Airport": [40.771814, -73.874552], "Newark Airport": [40.693034, -74.186161], "New York Times Co.": [40.777208, -73.827689], "42 st Manhattan": [40.757554, -73.990587], "Little Italy": [40.718680, -73.997613], "Bronx Zoo": [40.848611, -73.882631], "New York Botanical Garden": [40.861748, -73.880145], "Washington Square Park": [40.731371, -73.996997] }; (function($){ /* ** GMaps Big Distance Matrix functions, see package ** http://www.jsclasses.org/package/362-JavaScript-Get-Google-Maps-distance-matrix-for-many-locations.html */ Route_DistanceMatrix.init(Route_Points); Route_DistanceMatrix.displayTable("table_route_matrix"); Route_DistanceMatrix.startRouting(3000); $("body").on("click","#btnOptimize",function(evt){ evt.preventDefault(); /* ** Initialize the class. ** ** Route_Optimizer.init(distanceMatrix, optimizeBy, consoleDivId); ** ** Parameters: ** -- distanceMatrix: Object returned by the "GMaps Big Distance Matrix" (Required). ** -- optimizeBy: Select variable to optimize (Required, Possible values: 1 = distance, 2 = time, 3 = speed, distance/time). ** -- consoleDivId: DOM id of the container where the log information will be written. (Optional, Default value: false). ** */ /* ** Do Route Optimization. ** ** Route_Optimizer.doOptimize(maxIterations, numAnts, decayFactor, heuristicCoeff, greedinessFactor); ** ** Parameters: ** -- maxIterations: Number of iterations for find the solution. (Optional, typically a value between 200 and 500 times the numAnts value). ** -- numAnts: Number of ants (cars) that run the trials (Optional, a typical value is the half of locations plus one) ** -- decayFactor: Rate at which historic information is lost. (Optional, recommended values: 0.1-0.5, default value: random number between 0.1 & 0.5). ** -- heuristicCoeff: Controls the amount of contribution problem-specific heuristic information plays in a components probability of selection. (Optional, recommended values: 2-5, default value: random number between 2 & 5). ** -- greedinessFactor: Controls the amount of contribution problem-specific heuristic information plays in a components probability of selection. (Optional, recommended values: 0.8-1.3, default value: random number between 0.8 & 1.3). ** */ // Optimize by distance $("#console_route_matrix").append("<p><strong>Optimizing route by distance...</strong></p>"); Route_Optimizer.init(Route_DistanceMatrix.exportResults(), 1, "console_route_matrix"); setTimeout(function(){ var OptimalRoute = Route_Optimizer.doOptimize(); },10); /* // Optimize by time $("#console_route_matrix").append("<p><strong>Optimizing route by time...</strong></p>"); Route_Optimizer.init(Route_DistanceMatrix.exportResults(), 2, "console_route_matrix"); setTimeout(function(){ var OptimalRoute = Route_Optimizer.doOptimize(); },10); */ /* // Optimize by speed $("#console_route_matrix").append("<p><strong>Optimizing route by speed...</strong></p>"); Route_Optimizer.init(Route_DistanceMatrix.exportResults(), 3, "console_route_matrix"); setTimeout(function(){ var OptimalRoute = Route_Optimizer.doOptimize(); },10); */ }); $("body").on("click","#btnExport",function(evt){ evt.preventDefault(); var distanceMatrix = Route_DistanceMatrix.exportResults(true); $("#export_data_div").html(distanceMatrix); }); })(jQuery);

  Files folder image Files (7)  
File Role Description
Files folder imagecss (1 file)
Files folder imagejs (3 files)
Plain text file gmaps-routeoptimizer.js Class GMaps v3 Big Route Optimizer Class
Accessible without login Plain text file example.html Data Example of usage (HTML)
Accessible without login Plain text file example.js Example Example of usage (JS)

  Files folder image Files (7)  /  css  
File Role Description
  Accessible without login Plain text file bootstrap.min.css Data Bootstrap CSS minified

  Files folder image Files (7)  /  js  
File Role Description
  Plain text file gmaps-distancematrix.js Class Google Maps Big Distance Matrix class
  Accessible without login Plain text file jquery.min.js Aux. JQuery Library minified
  Accessible without login Plain text file json2.min.js Aux. JSON2 utility minified

 Version Control Unique User Downloads Download Rankings  
 0%
Total:193
This week:0
All time:260
This week:3Up