Hello all,
I am having an issue with a Javascriptlet task, I am using the Mapquest Traffic API and using an HTTP Get and it returns JSON like this:
{"incidents":[{"parameterizedDescription":{"crossRoad2":"Du Page Blvd / Carleton Ave","crossRoad1":"","position2":"","direction":"both ways","position1":"at","eventText":"Accident, approach With Care","toLocation":"Wheaton","roadName":"Carleton Ave"},"delayFromFreeFlow":0,"delayFromTypical":0,"fullDesc":"Accident on Carleton Ave both ways at Du Page Blvd. Approach with care.","severity":2,"lng":-88.053925,"shortDesc":"Carleton Ave : accident at Du Page Blvd","type":4,"endTime":"2015-01-20T12:57:00","id":"1301688167","startTime":"2015-01-20T12:05:29","distance":0,"impacting":false,"eventCode":201,"lat":41.862225,"iconURL":"http://api.mqcdn.com/mqtraffic/incid_mod.png"},{"parameterizedDescription":{"crossRoad2":"22nd St","crossRoad1":"","position2":"","direction":"both ways","position1":"around","eventText":"Accident, approach With Care","toLocation":"York","roadName":"22nd St"},"delayFromFreeFlow":0,"delayFromTypical":0,"fullDesc":"Accident on 22nd St both ways in York. Approach with care.","severity":2,"lng":-87.974945,"shortDesc":"22nd St : accident at 22nd St","type":4,"endTime":"2015-01-20T13:15:00","id":"375340284","startTime":"2015-01-20T11:44:06","distance":0.01,"impacting":false,"eventCode":201,"lat":41.846188,"iconURL":"http://api.mqcdn.com/mqtraffic/incid_mod.png"}],"mqURL":"http://www.mapquest.com/maps?traffic=1&latitude=41.8578326&longitude=-88.0039975","info":{"copyright":{"text":"© 2015 MapQuest, Inc.","imageUrl":"http://api.mqcdn.com/res/mqlogo.gif","imageAltText":"© 2015 MapQuest, Inc."},"statuscode":0,"messages":[]}}
I then set %traf to %HTTPD
Then I have a Javascriptlet: var data = (traf)
Then another Javascriptlet:
var homeTraffic = data.incidents;
var incidents;
if (homeTraffic.length === 0) {
var noTraffic = "There are no reported traffic incidents!";
setGlobal ("%homeIncidents", noTraffic );
} else {
for (var i = 0; i < homeTraffic.length; i++) {
var incidents = homeTraffic.fullDesc;
setGlobal ("%homeIncidents", incidents);
}
}
When I use it in the Chrome console it works perfectly. However in Tasker it does absolutely nothing.
I can use flashLong (data); and that works but any manipulation does not work at all.
Another weird thing is I had a different setup where I would write it all to a JS file and when I would do that it would fail the first time, however if I used ES File Explorer to open it and then disable everything in the task except for the link to the JS file it works and sets my variable correctly.
Any help would be greatly appreciated, I am starting to pull my hair out with this.
I have a Weather task that uses Wunderground Weather API and it works perfectly I am not sure why the Traffic one is not working.
Thanks,
Mike
I am having an issue with a Javascriptlet task, I am using the Mapquest Traffic API and using an HTTP Get and it returns JSON like this:
{"incidents":[{"parameterizedDescription":{"crossRoad2":"Du Page Blvd / Carleton Ave","crossRoad1":"","position2":"","direction":"both ways","position1":"at","eventText":"Accident, approach With Care","toLocation":"Wheaton","roadName":"Carleton Ave"},"delayFromFreeFlow":0,"delayFromTypical":0,"fullDesc":"Accident on Carleton Ave both ways at Du Page Blvd. Approach with care.","severity":2,"lng":-88.053925,"shortDesc":"Carleton Ave : accident at Du Page Blvd","type":4,"endTime":"2015-01-20T12:57:00","id":"1301688167","startTime":"2015-01-20T12:05:29","distance":0,"impacting":false,"eventCode":201,"lat":41.862225,"iconURL":"http://api.mqcdn.com/mqtraffic/incid_mod.png"},{"parameterizedDescription":{"crossRoad2":"22nd St","crossRoad1":"","position2":"","direction":"both ways","position1":"around","eventText":"Accident, approach With Care","toLocation":"York","roadName":"22nd St"},"delayFromFreeFlow":0,"delayFromTypical":0,"fullDesc":"Accident on 22nd St both ways in York. Approach with care.","severity":2,"lng":-87.974945,"shortDesc":"22nd St : accident at 22nd St","type":4,"endTime":"2015-01-20T13:15:00","id":"375340284","startTime":"2015-01-20T11:44:06","distance":0.01,"impacting":false,"eventCode":201,"lat":41.846188,"iconURL":"http://api.mqcdn.com/mqtraffic/incid_mod.png"}],"mqURL":"http://www.mapquest.com/maps?traffic=1&latitude=41.8578326&longitude=-88.0039975","info":{"copyright":{"text":"© 2015 MapQuest, Inc.","imageUrl":"http://api.mqcdn.com/res/mqlogo.gif","imageAltText":"© 2015 MapQuest, Inc."},"statuscode":0,"messages":[]}}
I then set %traf to %HTTPD
Then I have a Javascriptlet: var data = (traf)
Then another Javascriptlet:
var homeTraffic = data.incidents;
var incidents;
if (homeTraffic.length === 0) {
var noTraffic = "There are no reported traffic incidents!";
setGlobal ("%homeIncidents", noTraffic );
} else {
for (var i = 0; i < homeTraffic.length; i++) {
var incidents = homeTraffic.fullDesc;
setGlobal ("%homeIncidents", incidents);
}
}
When I use it in the Chrome console it works perfectly. However in Tasker it does absolutely nothing.
I can use flashLong (data); and that works but any manipulation does not work at all.
Another weird thing is I had a different setup where I would write it all to a JS file and when I would do that it would fail the first time, however if I used ES File Explorer to open it and then disable everything in the task except for the link to the JS file it works and sets my variable correctly.
Any help would be greatly appreciated, I am starting to pull my hair out with this.
I have a Weather task that uses Wunderground Weather API and it works perfectly I am not sure why the Traffic one is not working.
Thanks,
Mike