Showing
2 changed files
with
88 additions
and
2 deletions
... | @@ -318,8 +318,55 @@ router.get('/park', function(req, res) { | ... | @@ -318,8 +318,55 @@ router.get('/park', function(req, res) { |
318 | }) | 318 | }) |
319 | }); | 319 | }); |
320 | 320 | ||
321 | -router.get('/transport', function(req, res) { | 321 | +router.get('/transport', function (req, res) { |
322 | - let | 322 | + let apikey=process.env.ODSAY_APIKEY |
323 | + | ||
324 | + let bus_url = 'https://api.odsay.com/v1/api/pointSearch?lang=0&x=' + user_latitude + '&y=' + user_logitude + '&radius=500&stationClass=1&apiKey=' + apikey; | ||
325 | + let subway_url = 'https://api.odsay.com/v1/api/pointSearch?lang=0&x=' + user_latitude + '&y=' + user_logitude + '&radius=1000&stationClass=2&apiKey=' + apikey; | ||
326 | + let busCnt = 0; | ||
327 | + let subwayCnt=0; | ||
328 | + console.log(bus_url); | ||
329 | + | ||
330 | + | ||
331 | + request({ | ||
332 | + url: bus_url, | ||
333 | + method: 'GET' | ||
334 | + }, function (err, response, body) { | ||
335 | + | ||
336 | + if (!err && res.statusCode == 200) { | ||
337 | + //console.log("inside"); | ||
338 | + let bus_result = JSON.parse(body); | ||
339 | + //console.log(bus_result); | ||
340 | + let busStations = []; | ||
341 | + busCnt = bus_result.result.count; | ||
342 | + console.log('in!'); | ||
343 | + for (var i = 0; i < busCnt; i++) { | ||
344 | + busStations.push(bus_result.result.station[i].stationName); | ||
345 | + } | ||
346 | + console.log(busStations); | ||
347 | + request({ | ||
348 | + url: subway_url, | ||
349 | + method: 'GET' | ||
350 | + }, function (err, response, body) { | ||
351 | + if (!err && res.statusCode == 200) { | ||
352 | + let subway_result = JSON.parse(body); | ||
353 | + let subwayStations = []; | ||
354 | + subwayCnt = subway_result.result.count; | ||
355 | + console.log("지하철역 개수:" + subwayCnt); | ||
356 | + console.log('in3!'); | ||
357 | + for (var i = 0; i < subwayCnt; i++) { | ||
358 | + console.log(subway_result.result.station[i]); | ||
359 | + subwayStations.push(subway_result.result.station[i].stationName); | ||
360 | + } | ||
361 | + console.log(busStations); | ||
362 | + console.log(subwayStations); | ||
363 | + res.render('transport',{busCnt:busCnt, busStations:busStations, subwayCnt:subwayCnt, subwayStations:subwayStations, total:busCnt+subwayCnt}) | ||
364 | + } | ||
365 | + }) | ||
366 | + | ||
367 | + } | ||
368 | + }) | ||
369 | + | ||
323 | }); | 370 | }); |
324 | router.get('/safe', function(req, res) { | 371 | router.get('/safe', function(req, res) { |
325 | 372 | ... | ... |
views/transport.ejs
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html lang="ko"> | ||
3 | + | ||
4 | +<head> | ||
5 | + <meta charset="UTF-8"> | ||
6 | + <title>✍️ 결과 페이지</title> | ||
7 | +</head> | ||
8 | + | ||
9 | +<body> | ||
10 | + <h1> 대중교통 현황</h1> | ||
11 | + 주변 버스 정류장 : | ||
12 | + <%for (var i =0; i <busCnt; i++){%> | ||
13 | + <li> | ||
14 | + <%=busStations[i]%> | ||
15 | + </li> | ||
16 | + | ||
17 | + <%}%> | ||
18 | + <h3>총 버스정류장 개수 : | ||
19 | + <%=busCnt%> | ||
20 | + </h3> | ||
21 | + <h1> 지하철역 현황</h1> | ||
22 | + 주변 지하철역 : | ||
23 | + <%for (var i =0; i <subwayCnt; i++){%> | ||
24 | + <li> | ||
25 | + <%=subwayStations[i]%> | ||
26 | + </li> | ||
27 | + | ||
28 | + <%}%> | ||
29 | + <h3>총 지하철역 개수 : | ||
30 | + <%=subwayCnt%> | ||
31 | + </h3> | ||
32 | + <h3>총 대중교통 개수 : | ||
33 | + <%=total%> | ||
34 | + </h3> | ||
35 | + | ||
36 | + | ||
37 | +</body> | ||
38 | + | ||
39 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment