Skip to content

Instantly share code, notes, and snippets.

@afian
Created December 17, 2018 22:30
Show Gist options
  • Save afian/37960d4cae0ecee8ca814754dee0ed27 to your computer and use it in GitHub Desktop.
Save afian/37960d4cae0ecee8ca814754dee0ed27 to your computer and use it in GitHub Desktop.
Asynchronous Routific VRP call
function vrpLongCall() {
var params = {
visits: {
visit_1: {
location: {
name: "Jack Smith",
lat: 49.227607,
lng: -123.1363085
},
start: "8:00",
end: "16:00",
duration: 10
},
visit_2: {
location: {
name: "Bill Mayers",
lat: 49.227607,
lng: -123.1363085
},
start: "8:00",
end: "16:00",
duration: 10
},
visit_3: {
location: {
name: "Marc Kuo",
lat: 49.227607,
lng: -123.1363085
},
start: "8:00",
end: "16:00",
duration: 10
}
},
fleet: {
vehicle_1: {
start_location: {
id: "depot",
lat: 49.2553636,
lng: -123.0873365
}
}
}
}
$.ajax({
type:"POST",
url:"http://api.routific.com/v1/vrp-long",
headers: {
'Authorization':'bearer [add your api token here]',
'Content-Type':'application/json'
},
dataType: 'json',
data: JSON.stringify(params),
success: function(data) {
console.log(data);
vrpLongPoll(data.job_id);
}
});
}
function vrpLongPoll(jobId) {
$.ajax({
type:"GET",
url:"http://api.routific.com/v1/jobs/"+jobId,
headers: {
'Authorization':'bearer [add your api token here]',
'Content-Type':'application/json'
},
success: function(data) {
console.log(data);
if (data.status != 'finished') vrpLongPoll(jobId);
}
});
}
vrpLongCall();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment