안지영

complete transport category

......@@ -318,8 +318,55 @@ router.get('/park', function(req, res) {
})
});
router.get('/transport', function(req, res) {
let
router.get('/transport', function (req, res) {
let apikey=process.env.ODSAY_APIKEY
let bus_url = 'https://api.odsay.com/v1/api/pointSearch?lang=0&x=' + user_latitude + '&y=' + user_logitude + '&radius=500&stationClass=1&apiKey=' + apikey;
let subway_url = 'https://api.odsay.com/v1/api/pointSearch?lang=0&x=' + user_latitude + '&y=' + user_logitude + '&radius=1000&stationClass=2&apiKey=' + apikey;
let busCnt = 0;
let subwayCnt=0;
console.log(bus_url);
request({
url: bus_url,
method: 'GET'
}, function (err, response, body) {
if (!err && res.statusCode == 200) {
//console.log("inside");
let bus_result = JSON.parse(body);
//console.log(bus_result);
let busStations = [];
busCnt = bus_result.result.count;
console.log('in!');
for (var i = 0; i < busCnt; i++) {
busStations.push(bus_result.result.station[i].stationName);
}
console.log(busStations);
request({
url: subway_url,
method: 'GET'
}, function (err, response, body) {
if (!err && res.statusCode == 200) {
let subway_result = JSON.parse(body);
let subwayStations = [];
subwayCnt = subway_result.result.count;
console.log("지하철역 개수:" + subwayCnt);
console.log('in3!');
for (var i = 0; i < subwayCnt; i++) {
console.log(subway_result.result.station[i]);
subwayStations.push(subway_result.result.station[i].stationName);
}
console.log(busStations);
console.log(subwayStations);
res.render('transport',{busCnt:busCnt, busStations:busStations, subwayCnt:subwayCnt, subwayStations:subwayStations, total:busCnt+subwayCnt})
}
})
}
})
});
router.get('/safe', function(req, res) {
......
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>✍️ 결과 페이지</title>
</head>
<body>
<h1> 대중교통 현황</h1>
주변 버스 정류장 :
<%for (var i =0; i <busCnt; i++){%>
<li>
<%=busStations[i]%>
</li>
<%}%>
<h3>총 버스정류장 개수 :
<%=busCnt%>
</h3>
<h1> 지하철역 현황</h1>
주변 지하철역 :
<%for (var i =0; i <subwayCnt; i++){%>
<li>
<%=subwayStations[i]%>
</li>
<%}%>
<h3>총 지하철역 개수 :
<%=subwayCnt%>
</h3>
<h3>총 대중교통 개수 :
<%=total%>
</h3>
</body>
</html>
\ No newline at end of file