Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Very basic sample for google distance matrix
<!DOCTYPE html>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
var origin = "Colombo, Srilanka",
destination = "Stockholm, Sweden",
service = new google.maps.DistanceMatrixService();
origins: [origin],
destinations: [destination],
travelMode: google.maps.TravelMode.DRIVING,
avoidHighways: false,
avoidTolls: false
function callback(response, status) {
var orig = document.getElementById("orig"),
dest = document.getElementById("dest"),
dist = document.getElementById("dist");
if(status=="OK") {
dest.value = response.destinationAddresses[0];
orig.value = response.originAddresses[0];
dist.value = response.rows[0].elements[0].distance.text;
} else {
alert("Error: " + status);
Very simple HTML sample for using the Google Distance Matrix API.<br><br>
<table border="0">
<td><input id="orig" type="text" style="width:35em"></td>
<td><input id="dest" type="text" style="width:35em"></td>
<td><input id="dist" type="text" style="width:35em"></td>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment