-
Notifications
You must be signed in to change notification settings - Fork 0
/
广州实时公交查询.js
238 lines (227 loc) · 5.21 KB
/
广州实时公交查询.js
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
var lat;
var lng;
var bus = [];
var station = [];
var busNum;
getLocation();
$ui.render({
views: [
{
type: "button",
props: {
title: "公交查询"
},
layout: function(make, view) {
make.center.equalTo(view.super);
make.width.equalTo(120);
make.height.equalTo(60);
},
events: {
tapped: function(sender) {
getLocation();
bus = [];
station = [];
}
}
}
]
});
function getLocation() {
$location.fetch({
handler: function(result) {
lat = result.lat;
lng = result.lng;
console.info(lat + "," + lng);
getByGps();
}
});
}
function getByGps() {
$http.post({
url: "https://rycxapi.gci-china.com/xxt-api-v5.0/search/getByGPS.do",
header: {
"Content-Type": "application/json; charset=utf-8"
},
body: {
"Source": 0,
"data": { "Source": 0, "longitude": lng, "latitude": lat },
"appid": "rycxGci001",
"sign": "3A9B44F7BA05C4188AE58F72CA9108E098A6A671",
"reqpara": {
"Source": 0,
"speed": 0,
"uid": "0",
"direct": 0,
"devtype": 1,
"gpstime": 1541220821000,
"devno": "66850128-DFC6-4612-BEF1-CE88FD2BE2A0",
"version": "1.1.7",
"lat": lat,
"lng": lng
},
"reqtime": 1541220821000
},
handler: function(resp) {
var data = resp.data;
console.info(data);
console.info(data.retData.bus);
for (i in data.retData.bus) {
station.push({
"name": data.retData.bus[i].n,
"i": data.retData.bus[i].i
});
}
choseStation();
}
});
}
function getByStation(i) {
$http.post({
url:
"https://rycxapi.gci-china.com/xxt-api-v5.0/bus/routeStation/getByStation.do",
header: {
"Content-Type": "application/json; charset=utf-8"
},
body: {
"Source": 0,
"data": { "Source": 0, "stationNameId": i.toString() },
"appid": "rycxGci001",
"sign": "0171797E7A21FAB35608306880F6E06827CEF91C",
"reqpara": {
"Source": 0,
"speed": 0,
"uid": "0",
"direct": 0,
"devtype": 1,
"gpstime": 1541220827000,
"devno": "66850128-DFC6-4612-BEF1-CE88FD2BE2A0",
"version": "1.1.7",
"lat": lat,
"lng": lng
},
"reqtime": 1541220827000
},
handler: function(resp) {
var data = resp.data.retData.l;
console.info(data);
for (i in data) {
bus.push({
"name": data[i].rn + " " + data[i].dn,
"ri": data[i].ri,
"rsi": data[i].rsi,
"num": data[i].rn
});
}
choseBus();
}
});
}
function getByRouteIdAndDirection(ri) {
$http.post({
url:
"https://rycxapi.gci-china.com/xxt-api-v5.0/bus/route/getByRouteIdAndDirection.do",
header: {
"Content-Type": "application/json; charset=utf-8"
},
body: {
"Source": 0,
"data": {
"routeId": ri,
"direction": "0",
"Source": 0
},
"appid": "rycxGci001",
"sign": "6E678AFDE624EDD7AB39CA63A5B559E75A17F1B2",
"reqpara": {
"Source": 0,
"speed": 0,
"uid": "0",
"direct": 0,
"devtype": 1,
"gpstime": 1541220841000,
"devno": "66850128-DFC6-4612-BEF1-CE88FD2BE2A0",
"version": "1.1.7",
"lat": lat,
"lng": lng
},
"reqtime": 1541220841000
},
handler: function(resp) {
var data = resp.data;
console.info(data);
}
});
}
function getWaitTime(rsi) {
$http.post({
url: "https://rycxapi.gci-china.com/xxt-api-v5.0/bus/forecast/waitTime.do",
header: {
"Content-Type": "application/json; charset=utf-8"
},
body: {
"Source": 0,
"data": {
"num": 3,
"Source": 0,
"routeStationId": rsi
},
"appid": "rycxGci001",
"sign": "7E487758F744B3B85761F4785BD891BEE71CF5AD",
"reqpara": {
"Source": 0,
"speed": 0,
"uid": "0",
"direct": 0,
"devtype": 1,
"gpstime": 1541220841000,
"devno": "66850128-DFC6-4612-BEF1-CE88FD2BE2A0",
"version": "1.1.7",
"lat": lat,
"lng": lng
},
"reqtime": 1541220841000
},
handler: function(resp) {
var data = resp.data.retData.list[0];
console.info(data);
if (data.count != -1)
alert(
"下一班" +
busNum +
"还有" +
data.count +
"站,大约需要" +
data.time +
"分钟"
);
else alert("尚未发车");
}
});
}
function choseStation() {
$ui.toast("请选择一个公交站")
$ui.menu({
items: station.map(function(item) {
return item.name;
}),
handler: function(title, idx) {
var i = station[idx].i;
getByStation(i);
}
});
}
function choseBus() {
$ui.toast("请选择您查询的公交车");
$ui.menu({
items: bus.map(function(item) {
return item.name;
}),
handler: function(title, idx) {
busNum = bus[idx].num;
var ri = bus[idx].ri;
var rsi = bus[idx].rsi;
getByRouteIdAndDirection(ri);
getWaitTime(rsi);
}
});
}