Javascript object for fill Google Maps Distance Matrix for 25+ locations.
It can call the Google Maps v3 API to get the distance matrix for many locations that may go over the 25 locations limit by splitting it in smaller blocks.
The object can display the distance matrix on a HTML table or export it as a string in JSON format.
- Homepage: http://d-castillo.info/projects/gmaps-bigdistancematrix
- Source: https://github.com/davcs86/gmaps-bigdistancematrix
- Bugs: https://github.com/davcs86/gmaps-bigdistancematrix/issues
- DEMO: http://d-castillo.info/gmaps-bigdistancematrix/example.html
- Other: http://www.jsclasses.org/package/362
Find optimal routes with the retrieved data on:
Route Optimizer for Big Distance Matrix for Google Maps: https://github.com/davcs86/gmaps-bigrouteoptimizer
- jQuery 1.8+ http://jquery.com/
- JSON3 http://bestiejs.github.io/json3/
-
Define an object with the GPS latitude and longitude of the route points in an Object. From example.js
// 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], //... "Bronx Zoo": [40.848611, -73.882631], "New York Botanical Garden": [40.861748, -73.880145], "Washington Square Park": [40.731371, -73.996997] };
-
Initialize the object.
Route_DistanceMatrix.init(routePoints, consoleDivId, itemsPerReq, gTravelMode, gUnitSystem, gAvoidHighways, gAvoidTolls); //from example.js Route_DistanceMatrix.init(Route_Points,"console_route_matrix", 10);
Parameter Description routePoints Object with the GPS latitude and longitude of the places.
Mandatory.consoleDivId DOM id of the container where the log information will be written.
Optional. Default value: false.itemsPerReq Number of items to include per request to Google.
Optional. Default value: 5, Max Value 25.gTravelMode Google's parameter, view Google Maps Reference.
Optional. Default value: google.maps.TravelMode.DRIVING.gUnitSystem Google's parameter, view Google Maps Reference.
Optional. Default value: false.gAvoidTolls Google's parameter, view Google Maps Reference.
Optional. Default value: false.Google Maps v3 API Reference: https://developers.google.com/maps/documentation/javascript/distancematrix#distance_matrix_requests
-
Set the table where the data will be displayed.
Route_DistanceMatrix.displayTable(tableDomvId); //from example.js Route_DistanceMatrix.displayTable("table_route_matrix");
Parameter Description tableDomvId DOM id of the table where the data will be displayed.
Mandatory.NOTE: This function is OPTIONAL, you can populate the distance matrix without display any data. See function Route_DistanceMatrix.exportResults().
-
Start the matrix population.
Route_DistanceMatrix.startRouting(delayRequest); //from example.js Route_DistanceMatrix.startRouting(5000);
Parameter Description delayRequest Miliseconds between requests.
Optional. Default value: 1500 ms. -
Export the distance matrix as a JSON object.
var jsonObjResults = Route_DistanceMatrix.exportResults(asString); //from example.js var distanceMatrix = Route_DistanceMatrix.exportResults(true);
Parameter Description asString If it's true, returns the string representation of the JSON Object.
Optional. Default value: false. -
Use the data as you prefer. Check out an interesting application for this data on my another project https://github.com/davcs86/gmaps-bigrouteoptimizer where you can find an optimal route of these points using any of three variables: Time, Distance and Speed.
Drop me line on: http://d-castillo.info/contactme/ or to: davcs86@gmail.com
Did this project help you to save (or earn) some money?
Please, support to the author by making a small donation.