Suyeon Jung

Modify transport category

......@@ -6,12 +6,13 @@ require('dotenv').config();
/* GET home page. */
let SIGUN_CODE;
let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY;
let ODSAY_API_KEY = process.env.ODSAY_APIKEY;
let user_sigun;
let user_gu;
let user_dong;
let userLocation;
let user_latitude;
let user_logitude;
let user_longitude;
let sigun = [{
sigun_name: '가평군',
sigun_code: 41820
......@@ -186,8 +187,8 @@ router.post('/', function(req, res) {
var result = JSON.parse(body);
console.log('result', result);
user_latitude = result.documents[0].address.x;
user_logitude = result.documents[0].address.y;
console.log('위도, 경도', user_latitude, user_logitude);
user_longitude = result.documents[0].address.y;
console.log('위도, 경도', user_latitude, user_longitude);
}
})
res.render('category', { userLocation: userLocation });
......@@ -318,49 +319,48 @@ router.get('/park', function(req, res) {
})
});
router.get('/transport', function (req, res) {
let apikey=process.env.ODSAY_APIKEY
router.get('/transport', function(req, res) {
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 bus_url = 'https://api.odsay.com/v1/api/pointSearch?';
let subway_url = 'https://api.odsay.com/v1/api/pointSearch?';
let qs = `?lang=0&x=${user_latitude}&y=${user_longitude}&radius=1000&stationClass=2&apiKey=${ODSAY_API_KEY}`;
let busCnt = 0;
let subwayCnt=0;
let subwayCnt = 0;
console.log(bus_url);
request({
url: bus_url,
url: bus_url + qs,
method: 'GET'
}, function (err, response, body) {
}, function(err, response, body) {
if (!err && res.statusCode == 200) {
//console.log("inside");
let bus_result = JSON.parse(body);
//console.log(bus_result);
console.log('bus_result', bus_result.result.station);
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(bus_result.result)
for (let i = 0; i < bus_result.result.station.length; i++) {
station = bus_result.result.station[i];
console.log('station', station)
busStations.push(station);
}
console.log(busStations);
console.log('busStations', busStations);
request({
url: subway_url,
url: subway_url + qs,
method: 'GET'
}, function (err, response, body) {
}, 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('subway_result', subway_result);
for (let i = 0; i < subway_result.result.station.length; i++) {
station = subway_result.result.station[i];
subwayStations.push(station);
}
console.log(busStations);
console.log(subwayStations);
res.render('transport',{busCnt:busCnt, busStations:busStations, subwayCnt:subwayCnt, subwayStations:subwayStations, total:busCnt+subwayCnt})
console.log('subwayStaions', subwayStations);
res.render('transport_result', { busStations: busStations, subwayStations: subwayStations })
}
})
......
......@@ -9,28 +9,28 @@
<body>
<h1> 대중교통 현황</h1>
주변 버스 정류장 :
<%for (var i =0; i <busCnt; i++){%>
<%for (var i =0; i <busStations.length; i++){%>
<li>
<%=busStations[i]%>
<%=busStations[i].stationName%>
</li>
<%}%>
<h3>총 버스정류장 개수 :
<%=busCnt%>
<%=busStations.length%>
</h3>
<h1> 지하철역 현황</h1>
주변 지하철역 :
<%for (var i =0; i <subwayCnt; i++){%>
<%for (var i =0; i <subwayStations.length; i++){%>
<li>
<%=subwayStations[i]%>
<%=subwayStations[i].stationName%>
</li>
<%}%>
<h3>총 지하철역 개수 :
<%=subwayCnt%>
<%=subwayStations.length%>
</h3>
<h3>총 대중교통 개수 :
<%=total%>
<%=busStations.length + subwayStations.length%>
</h3>
......