select.js
1.2 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
var express = require('express');
var router = express.Router();
var request = require('request');
require('dotenv').config();
/* GET home page. */
// 사용자가 index 페이지에서 주소를 입력하고 넘어오면
router.post('/', function(req, res) {
console.log(req.body);
let userSi = req.body.si
let userKu = req.body.ku;
let userLocation = `${userSi} ${userKu}`;
let xyList = [];
console.log(userLocation);
let YOUR_API_KEY = process.env.KAKAO_APIKEY;
let kakaoOptions = {
url: 'https://dapi.kakao.com/v2/local/search/address.json',
method: 'GET',
headers: {
'Authorization': `KakaoAK ${YOUR_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);
xyList.push(result.documents[0].address.x);
xyList.push(result.documents[0].address.y);
console.log(xyList);
}
})
res.render('select', { 'si': req.body.si, 'ku': req.body.ku });
});
module.exports = router;