Suyeon Jung

Test result view

......@@ -8,14 +8,14 @@ let SIGUN_CODE;
let SIGUNDONG_CODE;
// 사용자가 index 페이지에서 주소를 입력하고 넘어오면
router.post('/', function (req, res) {
router.post('/', function(req, res) {
console.log(req.body);
let userLocation = req.body.userLocation;
// let userSi = req.body.si
// let userDong = req.body.dong;
let xyList = [];
let user_latitude;
let user_logitude;
console.log(userLocation);
// console.log(req);
let KAKAO_API_KEY = process.env.KAKAO_APIKEY;
let kakaoOptions = {
url: 'https://dapi.kakao.com/v2/local/search/address.json',
......@@ -28,43 +28,51 @@ router.post('/', function (req, res) {
},
encoding: 'UTF-8',
}
request(kakaoOptions, function (err, res, body) {
request(kakaoOptions, function(err, res, body) {
if (!err && res.statusCode == 200) {
var result = JSON.parse(body);
console.log('result', result);
x = result.documents[0].address.x;
y = result.documents[0].address.y;
user_latitude = result.documents[0].address.x;
user_logitude = result.documents[0].address.y;
console.log(user_latitude, user_logitude);
}
})
res.render('category', { userLocation: req.body.userLocation });
});
router.get('/food', function (req, res) {
router.get('/food', function(req, res) {
// 맛집 리스트 조회
let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY;
let sigun_cd = 41110;
let url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt';
let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}`;
let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}&Type=json`;
request({
url: url + qs,
method: 'GET'
}, function (err, response, body) {
}, function(err, response, body) {
if (!err && res.statusCode == 200) {
let re = body;
console.log(body);
res.send(re);
let food_result = JSON.parse(body);
let store_names = []
// console.log('정상출력여부', result)
// console.log('총 출력 개수', result.PlaceThatDoATasteyFoodSt[0].head[0].list_total_count);
for (let i = 0; i < 16; i++) {
// 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR)
store_name = food_result.PlaceThatDoATasteyFoodSt[1].row[i];
console.log('store_name', store_name);
store_names.push(store_name);
}
console.log('food_result', food_result)
res.render('result', { store_names: store_names });
}
});
});
router.get('/school', function (req, res) {
router.get('/school', function(req, res) {
res.send('This is school');
});
router.get('/park', function (req, res) {
router.get('/park', function(req, res) {
let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY;
let sigun_cd = 41110;
let cityparknum = 0;
......@@ -73,22 +81,20 @@ router.get('/park', function (req, res) {
request({
url: url + qs,
method: 'GET'
}, function (err, response, body) {
}, function(err, response, body) {
var park_result = JSON.parse(body);
if (park_result.CityPark[0].head[1].RESULT.CODE == 'INFO-000') {
cityparknum = park_result.CityPark[0].head[0].list_total_count;
console.log(cityparknum + "개의 도시공원이 존재합니다.");
res.send(String(cityparknum) + "개의 도시공원이 존재합니다.");
}
else{
} else {
res.send("도시공원이 없습니다.");
}
}
)
})
//res.send('This is park');
});
router.get('/shop', function (req, res) {
router.get('/shop', function(req, res) {
let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY;
let sigun_cd = 41110;
let mallnum = 0;
......@@ -97,21 +103,19 @@ router.get('/shop', function (req, res) {
request({
url: url + qs,
method: 'GET'
}, function (err, response, body) {
}, function(err, response, body) {
var shop_result = JSON.parse(body);
if (shop_result.MrktStoreM[0].head[1].RESULT.CODE == 'INFO-000') {
mallnum = shop_result.MrktStoreM[0].head[0].list_total_count;
console.log(mallnum + "개의 쇼핑몰이 존재합니다.");
res.send(String(mallnum) + "개의 쇼핑몰이 존재합니다.");
}
else{
} else {
res.send("쇼핑몰이 없습니다.");
}
}
)
})
});
router.get('/gym', function (req, res) {
router.get('/gym', function(req, res) {
let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY;
let sigun_cd = 41110;
let gymnum = 0;
......@@ -120,30 +124,28 @@ router.get('/gym', function (req, res) {
request({
url: url + qs,
method: 'GET'
}, function (err, response, body) {
}, function(err, response, body) {
var gym_result = JSON.parse(body);
if (gym_result.PhysicaFitnessTrainingPlace[0].head[1].RESULT.CODE == 'INFO-000') {
gymnum = gym_result.PhysicaFitnessTrainingPlace[0].head[0].list_total_count;
console.log(gymnum + "개의 체육관이 존재합니다.");
res.send(String(gymnum)+"개의 체육관이 존재합니다.");
}
else {
res.send(String(gymnum) + "개의 체육관이 존재합니다.");
} else {
console.log("주변에 체육관이 없습니다.");
res.send("주변에 체육관이 없습니다.");
}
}
)
})
});
router.get('/transport', function (req, res) {
router.get('/transport', function(req, res) {
res.send(BusCnt);
});
router.get('/safe', function (req, res) {
router.get('/safe', function(req, res) {
res.send('This is safe');
});
router.get('/culture', function (req, res) {
router.get('/culture', function(req, res) {
res.send('This is culture');
});
......
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>✍️ 결과 페이지</title>
</head>
<body>
<h1>🥘 맛집 현황 </h1>
<%for (var i =0; i <store_names.length; i++){%>
<li>
<%=store_names[i].RESTRT_NM%>
</li>
<%}%>
<h3>총 맛집 개수 :
<%=store_names.length%>
</h3>
<h1>🍔 패스트푸드점 현황 </h1>
</body>
</html>
\ No newline at end of file