Skip to content

Instantly share code, notes, and snippets.

@TravelTime-Frontend
Created February 21, 2023 13:16
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 TravelTime-Frontend/6dfc0a1c8b268ded6d989d54ba20a9cf to your computer and use it in GitHub Desktop.
Save TravelTime-Frontend/6dfc0a1c8b268ded6d989d54ba20a9cf to your computer and use it in GitHub Desktop.
// The request for Time Map. Reference: http://docs.traveltimeplatform.com/reference/time-map/
var request = {
// This will be a search where we depart a specified time.
departure_searches: [{
// The id is useful when you send multiple searches in one request. Since we create only one search it doesn't matter much since we expect only one result.
id: "first_location",
// The coordinates for the departure location in a hash. { lat: <lat>, lng: <lng> }
"coords": coords,
// The transportation type for this search. We will be using public transport.
transportation: {
type: "public_transport"
},
// The departure time in an ISO format.
departure_time: departureTime,
// Travel time in seconds.
travel_time: travelTime
}],
// We will not be creating any shapes with a specified arrival time in this example so the array is empty.
arrival_searches: []
};
$.ajax({
// The URL for the Time Map endpoint.
url: "http://api.traveltimeapp.com/v4/time-map",
// We will need to send a POST request.
type: "post",
// The authentification headers.
"headers": headers,
// The request body in a JSON format.
data: JSON.stringify(request),
contentType: "application/json; charset=UTF-8",
success: function (data) {
// Here we handle the response from Time Map
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment