Showing
2 changed files
with
35 additions
and
35 deletions
... | @@ -6,12 +6,13 @@ require('dotenv').config(); | ... | @@ -6,12 +6,13 @@ require('dotenv').config(); |
6 | /* GET home page. */ | 6 | /* GET home page. */ |
7 | let SIGUN_CODE; | 7 | let SIGUN_CODE; |
8 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; | 8 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; |
9 | +let ODSAY_API_KEY = process.env.ODSAY_APIKEY; | ||
9 | let user_sigun; | 10 | let user_sigun; |
10 | let user_gu; | 11 | let user_gu; |
11 | let user_dong; | 12 | let user_dong; |
12 | let userLocation; | 13 | let userLocation; |
13 | let user_latitude; | 14 | let user_latitude; |
14 | -let user_logitude; | 15 | +let user_longitude; |
15 | let sigun = [{ | 16 | let sigun = [{ |
16 | sigun_name: '가평군', | 17 | sigun_name: '가평군', |
17 | sigun_code: 41820 | 18 | sigun_code: 41820 |
... | @@ -186,8 +187,8 @@ router.post('/', function(req, res) { | ... | @@ -186,8 +187,8 @@ router.post('/', function(req, res) { |
186 | var result = JSON.parse(body); | 187 | var result = JSON.parse(body); |
187 | console.log('result', result); | 188 | console.log('result', result); |
188 | user_latitude = result.documents[0].address.x; | 189 | user_latitude = result.documents[0].address.x; |
189 | - user_logitude = result.documents[0].address.y; | 190 | + user_longitude = result.documents[0].address.y; |
190 | - console.log('위도, 경도', user_latitude, user_logitude); | 191 | + console.log('위도, 경도', user_latitude, user_longitude); |
191 | } | 192 | } |
192 | }) | 193 | }) |
193 | res.render('category', { userLocation: userLocation }); | 194 | res.render('category', { userLocation: userLocation }); |
... | @@ -318,49 +319,48 @@ router.get('/park', function(req, res) { | ... | @@ -318,49 +319,48 @@ router.get('/park', function(req, res) { |
318 | }) | 319 | }) |
319 | }); | 320 | }); |
320 | 321 | ||
321 | -router.get('/transport', function (req, res) { | 322 | +router.get('/transport', function(req, res) { |
322 | - let apikey=process.env.ODSAY_APIKEY | ||
323 | 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; | 324 | + |
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; | 325 | + let bus_url = 'https://api.odsay.com/v1/api/pointSearch?'; |
326 | + let subway_url = 'https://api.odsay.com/v1/api/pointSearch?'; | ||
327 | + let qs = `?lang=0&x=${user_latitude}&y=${user_longitude}&radius=1000&stationClass=2&apiKey=${ODSAY_API_KEY}`; | ||
326 | let busCnt = 0; | 328 | let busCnt = 0; |
327 | - let subwayCnt=0; | 329 | + let subwayCnt = 0; |
328 | console.log(bus_url); | 330 | console.log(bus_url); |
329 | 331 | ||
330 | - | ||
331 | request({ | 332 | request({ |
332 | - url: bus_url, | 333 | + url: bus_url + qs, |
333 | method: 'GET' | 334 | method: 'GET' |
334 | - }, function (err, response, body) { | 335 | + }, function(err, response, body) { |
335 | - | 336 | + |
336 | if (!err && res.statusCode == 200) { | 337 | if (!err && res.statusCode == 200) { |
337 | //console.log("inside"); | 338 | //console.log("inside"); |
338 | let bus_result = JSON.parse(body); | 339 | let bus_result = JSON.parse(body); |
339 | - //console.log(bus_result); | 340 | + console.log('bus_result', bus_result.result.station); |
340 | let busStations = []; | 341 | let busStations = []; |
341 | - busCnt = bus_result.result.count; | 342 | + console.log(bus_result.result) |
342 | - console.log('in!'); | 343 | + for (let i = 0; i < bus_result.result.station.length; i++) { |
343 | - for (var i = 0; i < busCnt; i++) { | 344 | + station = bus_result.result.station[i]; |
344 | - busStations.push(bus_result.result.station[i].stationName); | 345 | + console.log('station', station) |
346 | + busStations.push(station); | ||
345 | } | 347 | } |
346 | - console.log(busStations); | 348 | + console.log('busStations', busStations); |
347 | request({ | 349 | request({ |
348 | - url: subway_url, | 350 | + url: subway_url + qs, |
349 | method: 'GET' | 351 | method: 'GET' |
350 | - }, function (err, response, body) { | 352 | + }, function(err, response, body) { |
351 | if (!err && res.statusCode == 200) { | 353 | if (!err && res.statusCode == 200) { |
352 | let subway_result = JSON.parse(body); | 354 | let subway_result = JSON.parse(body); |
353 | let subwayStations = []; | 355 | let subwayStations = []; |
354 | - subwayCnt = subway_result.result.count; | 356 | + console.log('subway_result', subway_result); |
355 | - console.log("지하철역 개수:" + subwayCnt); | 357 | + for (let i = 0; i < subway_result.result.station.length; i++) { |
356 | - console.log('in3!'); | 358 | + station = subway_result.result.station[i]; |
357 | - for (var i = 0; i < subwayCnt; i++) { | 359 | + subwayStations.push(station); |
358 | - console.log(subway_result.result.station[i]); | ||
359 | - subwayStations.push(subway_result.result.station[i].stationName); | ||
360 | } | 360 | } |
361 | console.log(busStations); | 361 | console.log(busStations); |
362 | - console.log(subwayStations); | 362 | + console.log('subwayStaions', subwayStations); |
363 | - res.render('transport',{busCnt:busCnt, busStations:busStations, subwayCnt:subwayCnt, subwayStations:subwayStations, total:busCnt+subwayCnt}) | 363 | + res.render('transport_result', { busStations: busStations, subwayStations: subwayStations }) |
364 | } | 364 | } |
365 | }) | 365 | }) |
366 | 366 | ... | ... |
... | @@ -9,28 +9,28 @@ | ... | @@ -9,28 +9,28 @@ |
9 | <body> | 9 | <body> |
10 | <h1> 대중교통 현황</h1> | 10 | <h1> 대중교통 현황</h1> |
11 | 주변 버스 정류장 : | 11 | 주변 버스 정류장 : |
12 | - <%for (var i =0; i <busCnt; i++){%> | 12 | + <%for (var i =0; i <busStations.length; i++){%> |
13 | <li> | 13 | <li> |
14 | - <%=busStations[i]%> | 14 | + <%=busStations[i].stationName%> |
15 | </li> | 15 | </li> |
16 | 16 | ||
17 | <%}%> | 17 | <%}%> |
18 | <h3>총 버스정류장 개수 : | 18 | <h3>총 버스정류장 개수 : |
19 | - <%=busCnt%> | 19 | + <%=busStations.length%> |
20 | </h3> | 20 | </h3> |
21 | <h1> 지하철역 현황</h1> | 21 | <h1> 지하철역 현황</h1> |
22 | 주변 지하철역 : | 22 | 주변 지하철역 : |
23 | - <%for (var i =0; i <subwayCnt; i++){%> | 23 | + <%for (var i =0; i <subwayStations.length; i++){%> |
24 | <li> | 24 | <li> |
25 | - <%=subwayStations[i]%> | 25 | + <%=subwayStations[i].stationName%> |
26 | </li> | 26 | </li> |
27 | 27 | ||
28 | <%}%> | 28 | <%}%> |
29 | <h3>총 지하철역 개수 : | 29 | <h3>총 지하철역 개수 : |
30 | - <%=subwayCnt%> | 30 | + <%=subwayStations.length%> |
31 | </h3> | 31 | </h3> |
32 | <h3>총 대중교통 개수 : | 32 | <h3>총 대중교통 개수 : |
33 | - <%=total%> | 33 | + <%=busStations.length + subwayStations.length%> |
34 | </h3> | 34 | </h3> |
35 | 35 | ||
36 | 36 | ... | ... |
-
Please register or login to post a comment