Created
December 17, 2018 22:30
-
-
Save afian/37960d4cae0ecee8ca814754dee0ed27 to your computer and use it in GitHub Desktop.
Asynchronous Routific VRP call
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 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