jQuery.getJSON demo
You cannot use ajax to access googles maps api. It will give you an unknown error response but in reality its an "access denied" due to CORS. The below code will give you valid data for the route between brooklyn and queens, driving, in metrics
var directionsService = new google.maps.DirectionsService();
var directionsRequest = {
origin: "brooklyn",
destination: "queens",
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC
};
directionsService.route(directionsRequest, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
//do work with response data
}
else
//Error has occured
})
reference: http://www.sitepoint.com/find-a-route-using-the-geolocation-and-the-google-maps-api/