Skip to content

Commit 164ca72

Browse files
committed
Trying to use Traffic APIs, but they all suck.
1 parent 557cfa6 commit 164ca72

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

Resources/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ var NavDirView = require('views/nav_directions_view');
2222
var Events = require('controller/events');
2323
var Markers = require('controller/markers');
2424
var NavDirections = require('controller/nav_directions');
25-
var Cyclists = require('controller/cyclists')
25+
var Cyclists = require('controller/cyclists');
26+
var Traffic = require('controller/traffic_controller');
2627

2728
/* * * * * * * * * * * * * * * * * * * * *
2829
*
@@ -175,7 +176,9 @@ var nav_dir_start = nav_dir_view.getStartButton();
175176
cyclists
176177
);
177178
var markers = new Markers(mainMap);
179+
var traffic = new Traffic();
178180
markers.retrieveAndAddMarkers();
181+
traffic.getIncidents();
179182

180183
/* * * * * * * * * * * * * * * * * * * * *
181184
*
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)