Suyeon Jung

Add latitude and longitude update for select

...@@ -115,4 +115,7 @@ dist ...@@ -115,4 +115,7 @@ dist
115 .yarn/unplugged 115 .yarn/unplugged
116 .yarn/build-state.yml 116 .yarn/build-state.yml
117 .yarn/install-state.gz 117 .yarn/install-state.gz
118 -.pnp.*
...\ No newline at end of file ...\ No newline at end of file
118 +.pnp.*
119 +
120 +# dotenv environment variables file
121 +.env
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
8 "dependencies": { 8 "dependencies": {
9 "cookie-parser": "~1.4.4", 9 "cookie-parser": "~1.4.4",
10 "debug": "~2.6.9", 10 "debug": "~2.6.9",
11 + "dotenv": "^8.2.0",
11 "express": "~4.16.1", 12 "express": "~4.16.1",
12 "http-errors": "~1.6.3", 13 "http-errors": "~1.6.3",
13 "morgan": "~1.9.1", 14 "morgan": "~1.9.1",
......
1 var express = require('express'); 1 var express = require('express');
2 var router = express.Router(); 2 var router = express.Router();
3 var request = require('request'); 3 var request = require('request');
4 +require('dotenv').config();
4 5
5 /* GET home page. */ 6 /* GET home page. */
6 7
8 +// 사용자가 index 페이지에서 주소를 입력하고 넘어오면
7 router.post('/', function(req, res) { 9 router.post('/', function(req, res) {
10 + console.log(req.body);
11 + let userSi = req.body.si
12 + let userKu = req.body.ku;
13 + let userLocation = `${userSi} ${userKu}`;
14 + let xyList = [];
15 + console.log(userLocation);
16 + let YOUR_API_KEY = process.env.KAKAO_APIKEY;
8 let kakaoOptions = { 17 let kakaoOptions = {
9 - url: 'https://dapi.kakao.com/v2/local/search/address.json?query=잠실역', 18 + url: 'https://dapi.kakao.com/v2/local/search/address.json',
10 method: 'GET', 19 method: 'GET',
11 headers: { 20 headers: {
12 - 'Authorization': 'KakaoAK 4803a487ea1fb1646e4a8dd8c002ad7d' 21 + 'Authorization': `KakaoAK ${YOUR_API_KEY}`
22 + },
23 + qs: {
24 + query: userLocation
13 }, 25 },
14 - // qs: {
15 - // query: '잠실역'
16 - // },
17 encoding: 'UTF-8', 26 encoding: 'UTF-8',
18 } 27 }
19 request(kakaoOptions, function(err, res, body) { 28 request(kakaoOptions, function(err, res, body) {
20 if (!err && res.statusCode == 200) { 29 if (!err && res.statusCode == 200) {
21 - console.log(JSON.parse(body)); 30 + var result = JSON.parse(body);
31 + console.log('result', result);
32 + xyList.push(result.documents[0].address.x);
33 + xyList.push(result.documents[0].address.y);
34 + console.log(xyList);
22 } 35 }
23 }) 36 })
24 res.render('select', { 'si': req.body.si, 'ku': req.body.ku }); 37 res.render('select', { 'si': req.body.si, 'ku': req.body.ku });
......