-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
117 lines (85 loc) · 2.55 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html>
<head>
<title>Bing Traffic api test</title>
<style type="text/css">
input[type="text"] {
width: 250px;
}
</style>
<script type="text/javascript" src="lib/date.js"></script>
<script type="text/javascript" src="lib/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="bing-traffic.js"></script>
<script type="text/javascript">
var trafficInterval = null;
$(function(){
var traffic = new shr.maps.bingTraffic({
'bingApiKey':''
});
$("#start-calculating").click(function(){
$("#time-and-distance > tbody").html("");
var start = $("#start-location").val();
var finish = $("#end-location").val();
if(start !== "" && finish !== ""){
$("#start-calculating").hide();
$("#stop-calculating").show();
if(trafficInterval != null) {
clearInterval(trafficInterval);
trafficInterval = null;
}
traffic.calculate_driveTime(start, finish, onSuccess, onFailure);
trafficInterval = setInterval(function(){
traffic.calculate_driveTime(start, finish, onSuccess, onFailure);
}, 60000);
}
});
$("#stop-calculating").click(function(){
$("#start-calculating").show();
$("#stop-calculating").hide();
clearInterval(trafficInterval);
trafficInterval = null;
});
});
function onSuccess(data) {
$.each(data, function(index, item){
var minutesTravel = item.time / 60;
var hoursTravel = minutesTravel / 60;
var timeFormat = "h:mm tt";
var str = "<tr>";
str += "<td>" + item.departure.toString(timeFormat) + "</td>";
str += "<td>" + item.arrival.toString(timeFormat) + "</td>";
str += ("<td>" + minutesTravel.toFixed(2) + "</td>");
str += ("<td>" + item.distance.toFixed(2) + "</td>");
str += ("<td>" + (item.distance / hoursTravel).toFixed(2) + "</td>");
str += "</tr>"
$("#time-and-distance > tbody").append(str);
});
}
function onFailure(){
}
</script>
</head>
<body>
<div>
<label for="start-location">Start Location</label>
<input type="text" id="start-location" />
<label for="end-location">End Location</label>
<input type="text" id="end-location"/>
<input type="button" value="Start Calculating" id="start-calculating" />
<input type="button" value="Stop Calculating" id="stop-calculating" style="display:none;" />
</div>
<table id="time-and-distance">
<thead>
<tr>
<td>Departure</td>
<td>Arrival</td>
<td>Time (min.)</td>
<td>Distance (mi.)</td>
<td>MPH</td>
<tr>
<thead>
<tbody>
</tbody>
</table>
</body>
</html>