Skip to content

Instantly share code, notes, and snippets.

@derekeder
Created June 19, 2013 21:31
Show Gist options
  • Save derekeder/5818273 to your computer and use it in GitHub Desktop.
Save derekeder/5818273 to your computer and use it in GitHub Desktop.
Using Fusion Tables API with Google Distance Matrix API. This code is meant to be added to maps_lib.js
queryPointDistances: function(whereClause) {
MapsLib.query("'latitude', 'longitude'", whereClause,"MapsLib.getPointDistances");
},
getPointDistances: function(json) {
MapsLib.handleError(json);
var data = json["rows"];
var destinations = [];
var service = new google.maps.DistanceMatrixService();
for (var row in data) {
destinations[row] = new google.maps.LatLng(data[row][0], data[row][1]); // make a lat/long point
}
service.getDistanceMatrix(
{
origins: [MapsLib.currentPinpoint], // where we searched
destinations: destinations,
travelMode: google.maps.TravelMode.DRIVING,
avoidHighways: false,
avoidTolls: false
}, pointDistanceCallback);
},
pointDistanceCallback: function(response, status) {
// See Parsing the Results for
// the basics of a callback function.
// https://developers.google.com/maps/documentation/javascript/distancematrix#distance_matrix_parsing_the_results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment