1

I am trying to send a request to Travel Time Platform for an isochrone using the API - https://www.traveltimeplatform.com/

// Coordinates for Manchester Central Foodbank in Lat Lng
    var ManchesterCentralFoodbank = "53.464774, -2.23179";

    // The departure time in an ISO format 
    var departureTime = "2019-12-04T09:00:00-0500";
    // Travel time in seconds. We want 1 hour travel time so it is 60 minutes x 60 seconds.
    var travelTime = 60 * 60;

    const url = "https://api.traveltimeapp.com/v4/time-map";


    // API key and ID
    var APPLICATION_ID = "hidden_here";
    var API_KEY = "hidden_here";

    var request = {
        departure_searches: [{
        id: "starting_location",
        coords: ManchesterCentralFoodbank,
        transportation: {
            type: "public_transport", },

            departure_time: departureTime,
            travel_time: travelTime, }],

    arrival_searches: [] };


    // This function sends the request and draws the result onto the map
    function sendIsochrone(url, drawIsochrone) {

    let xhttp = new XMLHttpRequest();
        // event listener for when the HTTP state changes
        xhttp.onreadystatechange = function () {

        //a successful HTTP request returns a state of DONE and a status of 200
        if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
        drawIsochrone(JSON.parse(xhttp.responseText));
        }
      };

    // the request itself
    xhttp.open("POST", url)
    xhttp.setRequestHeader("X-Application-Id", APPLICATION_ID);
    xhttp.setRequestHeader("X-Api-Key", API_KEY);
    xhttp.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
    xhttp.responseType = "json";

    // passes the information stated in the request variable
    xhttp.send(JSON.stringify(request));

    }

    function drawIsochrone(data) {

        console.log(data)

    }

I keep getting a CORS error message - "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file" - I cant see any problems with my code and I am not sure where I'm going wrong.

I tried making these changes to my firefox browser https://support.mozilla.org/en-US/questions/1264280 but to no avail.

0

Browse other questions tagged or ask your own question.