category.js
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var express = require('express');
var router = express.Router();
var request = require('request');
require('dotenv').config();
/* GET home page. */
let SIGUN_CODE;
let SIGUNDONG_CODE;
// 사용자가 index 페이지에서 주소를 입력하고 넘어오면
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 = [];
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',
method: 'GET',
headers: {
'Authorization': `KakaoAK ${KAKAO_API_KEY}`
},
qs: {
query: userLocation
},
encoding: 'UTF-8',
}
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;
}
})
res.render('category', { userLocation: req.body.userLocation });
});
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}`;
request({
url: url + qs,
method: 'GET'
}, function(err, response, body) {
if (!err && res.statusCode == 200) {
let re = body;
console.log(body);
res.send(re);
}
});
});
router.get('/school', function(req, res) {
res.send('This is school');
});
router.get('/park', function(req, res) {
res.send('This is park');
});
router.get('/transport', function(req, res) {
res.send(BusCnt);
});
router.get('/safe', function(req, res) {
res.send('This is safe');
});
router.get('/culture', function(req, res) {
res.send('This is culture');
});
module.exports = router;