Skip to content

Instantly share code, notes, and snippets.

@BenFausch
Created March 5, 2018 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenFausch/2e646f2545e926def9ec5fb3423ba1b4 to your computer and use it in GitHub Desktop.
Save BenFausch/2e646f2545e926def9ec5fb3423ba1b4 to your computer and use it in GitHub Desktop.
Basic proximity/driving directions using the google maps api, returns JSON
var origin1 = new google.maps.LatLng(55.930385, -3.118425);
var origin2 = 'Greenwich, England';
var destinationA = 'Stockholm, Sweden';
var destinationB = new google.maps.LatLng(50.087692, 14.421150);
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [origin1, origin2],
destinations: [destinationA, destinationB],
travelMode: 'DRIVING',
}, callback);
function callback(response, status) {
// See Parsing the Results for
// the basics of a callback function.
console.log(response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment