Created
February 21, 2023 08:14
-
-
Save TravelTime-Frontend/8af24c774fd238465ff6679b68ec218e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendTimeMapRequest(geocodingResponse) { | |
// The request for Time Map. Reference: http://docs.traveltimeplatform.com/reference/time-map/ | |
var coords = geocodingResponse.features[0].geometry.coordinates; | |
var latLng = { lat: coords[1], lng: coords[0] }; | |
var request = { | |
departure_searches: [{ | |
id: "first_location", | |
coords: latLng, | |
transportation: { | |
type: "public_transport" | |
}, | |
departure_time: departureTime, | |
travel_time: travelTime | |
}], | |
arrival_searches: [] | |
}; | |
var xhr = new XMLHttpRequest() | |
xhr.addEventListener("readystatechange", function () { | |
if (this.readyState === 4) { | |
drawTimeMap(mymap, this.response); | |
} | |
}); | |
xhr.open("POST", "https://api.traveltimeapp.com/v4/time-map") | |
xhr.setRequestHeader("X-Application-Id", APPLICATION_ID); | |
xhr.setRequestHeader("X-Api-Key", API_KEY); | |
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); | |
xhr.responseType = "json"; | |
xhr.send(JSON.stringify(request)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment