|
| 1 | +var constants = require('./controller_constants'); |
| 2 | +var apiConstants = require('../api_constants'); |
| 3 | + |
| 4 | +var TrafficController = function() { |
| 5 | + this.incidentsReady = false; |
| 6 | +}; |
| 7 | + |
| 8 | +TrafficController.prototype.getIncidents = function(lat, long) { |
| 9 | + var boundingBox = "42.459260,-71.333157,42.298215,-70.929924"; |
| 10 | + |
| 11 | + mapQuest(); |
| 12 | + tomTom(); |
| 13 | + |
| 14 | + function mapQuest() { |
| 15 | + var req = "http://www.mapquestapi.com/traffic/v2/incidents?key=" + apiConstants.apiKeyMapquest + |
| 16 | + "&callback=handleIncidentsResponse&boundingBox=" + boundingBox + |
| 17 | + "&filters=construction,incidents&inFormat=kvp&outFormat=json"; |
| 18 | + |
| 19 | + var self = this; |
| 20 | + var client = Ti.Network.createHTTPClient({ |
| 21 | + onload : function(e) { |
| 22 | + Ti.API.info(this.responseText); |
| 23 | + }, |
| 24 | + onerror : function(e) { |
| 25 | + alert('Could not retrieve markers!'); |
| 26 | + }, |
| 27 | + timeout : constants.timeoutReq |
| 28 | + }); |
| 29 | + |
| 30 | + // Send request |
| 31 | + client.open("GET", encodeURI(req)); |
| 32 | + client.send(); |
| 33 | + } |
| 34 | + |
| 35 | + function tomTom() { |
| 36 | + var req = "https://api.tomtom.com/lbs/services/trafficIcons/3/s3/" + boundingBox + |
| 37 | + "/11/1335294634919/json?key=" + apiConstants.apiKeyTomTom + |
| 38 | + "&language=en"; |
| 39 | + var self = this; |
| 40 | + var client = Ti.Network.createHTTPClient({ |
| 41 | + onload : function(e) { |
| 42 | + Ti.API.info(this.responseText); |
| 43 | + }, |
| 44 | + onerror : function(e) { |
| 45 | + alert('Could not retrieve markers!'); |
| 46 | + }, |
| 47 | + timeout : constants.timeoutReq |
| 48 | + }); |
| 49 | + |
| 50 | + // Send request |
| 51 | + client.open("GET", encodeURI(req)); |
| 52 | + client.send(); |
| 53 | + } |
| 54 | + |
| 55 | +}; |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +module.exports = TrafficController; |
| 61 | + |
0 commit comments