/**
* The following example aims at illustrating Navitia’s journey feature.
* It requests an itinerary from a cool spot (our headquarter in Paris)
* to another cool spot (the Eiffel Tower, Paris).
* Please note that the transportation data that is used for this sandbox
* is only an example for demo purposes an does not reflect
* the actual transportation supply on the Parisian area.
*/
$.ajax({
type: 'GET',
url: 'https://api.navitia.io/v1/coverage/sandbox/journeys?from=2.3749036;48.8467927&to=2.2922926;48.8583736',
dataType: 'json',
headers: {
Authorization: 'Basic ' + btoa('a61f4cd8-3007-4557-9f4c-214969369cca')
},
success: function(result) {
displayJourney(result.journeys[0]);
$("#raw-result").html(pretty.json.prettyPrint(result));
},
error: function(xhr, textStatus, errorThrown) {
$("#raw-result").html('Error: ' + textStatus + ' ' + errorThrown);
}
});
function displayJourney(journey) {
var $tbody = $('tbody');
$.each(journey.sections, function(index, section) {
var $tr = $('<tr>');
$tr.append($('<td>').html(index));
$tr.append($('<td>').html(formatHour(section.departure_date_time)));
$tr.append($('<td>').html(formatHour(section.arrival_date_time)));
$tr.append($('<td>').html(section.from && section.from.name));
$tr.append($('<td>').html(section.to && section.to.name));
$tr.append($('<td>').html(section.mode));
$tr.append($('<td>').html(section.type));
$tr.append($('<td>').html(section.display_informations && section.display_informations.physical_mode));
$tr.append($('<td>').html(section.display_informations && section.display_informations.code));
$tbody.append($tr);
});
}
function formatHour(navitiaDate) {
return navitiaDate.substr(9).match(/.{2}/g).join(':');
}
if (!pretty)
var pretty = {};
pretty.json = {
replacer: function(match, pIndent, pKey, pVal, pEnd) {
var key = '<span class=json-key>';
var val = '<span class=json-value>';
var str =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.