Showing
1 changed file
with
172 additions
and
37 deletions
... | @@ -5,36 +5,172 @@ require('dotenv').config(); | ... | @@ -5,36 +5,172 @@ require('dotenv').config(); |
5 | 5 | ||
6 | /* GET home page. */ | 6 | /* GET home page. */ |
7 | let SIGUN_CODE; | 7 | let SIGUN_CODE; |
8 | -let SIGUNDONG_CODE; | 8 | +let user_latitude; |
9 | +let user_logitude; | ||
10 | +let sigun = [{ | ||
11 | + sigun_name: '가평군', | ||
12 | + sigun_code: 41820 | ||
13 | + }, | ||
14 | + { | ||
15 | + sigun_name: '경기도', | ||
16 | + sigun_code: 41000 | ||
17 | + }, | ||
18 | + { | ||
19 | + sigun_name: '고양시', | ||
20 | + sigun_code: 41280 | ||
21 | + }, | ||
22 | + { | ||
23 | + sigun_name: '과천시', | ||
24 | + sigun_code: 41290 | ||
25 | + }, | ||
26 | + { | ||
27 | + sigun_name: '광명시', | ||
28 | + sigun_code: 41210 | ||
29 | + }, | ||
30 | + { | ||
31 | + sigun_name: '광주시', | ||
32 | + sigun_code: 41610 | ||
33 | + }, | ||
34 | + { | ||
35 | + sigun_name: '구리시', | ||
36 | + sigun_code: 41310 | ||
37 | + }, | ||
38 | + { | ||
39 | + sigun_name: '군포시', | ||
40 | + sigun_code: 41410 | ||
41 | + }, | ||
42 | + { | ||
43 | + sigun_name: '김포시', | ||
44 | + sigun_code: 41570 | ||
45 | + }, | ||
46 | + { | ||
47 | + sigun_name: '남양주시', | ||
48 | + sigun_code: 41360 | ||
49 | + }, | ||
50 | + { | ||
51 | + sigun_name: '동두천시', | ||
52 | + sigun_code: 41250 | ||
53 | + }, | ||
54 | + { | ||
55 | + sigun_name: '부천시', | ||
56 | + sigun_code: 41190 | ||
57 | + }, | ||
58 | + { | ||
59 | + sigun_name: '성남시', | ||
60 | + sigun_code: 41130 | ||
61 | + }, | ||
62 | + { | ||
63 | + sigun_name: '수원시', | ||
64 | + sigun_code: 41110 | ||
65 | + }, | ||
66 | + { | ||
67 | + sigun_name: '시흥시', | ||
68 | + sigun_code: 41390 | ||
69 | + }, | ||
70 | + { | ||
71 | + sigun_name: '안산시', | ||
72 | + sigun_code: 41270 | ||
73 | + }, | ||
74 | + { | ||
75 | + sigun_name: '안성시', | ||
76 | + sigun_code: 41550 | ||
77 | + }, | ||
78 | + { | ||
79 | + sigun_name: '안양시', | ||
80 | + sigun_code: 41170 | ||
81 | + }, | ||
82 | + { | ||
83 | + sigun_name: '양주시', | ||
84 | + sigun_code: 41630 | ||
85 | + }, | ||
86 | + { | ||
87 | + sigun_name: '양평군', | ||
88 | + sigun_code: 41830 | ||
89 | + }, | ||
90 | + { | ||
91 | + sigun_name: '여주시', | ||
92 | + sigun_code: 41670 | ||
93 | + }, | ||
94 | + { | ||
95 | + sigun_name: '연천군', | ||
96 | + sigun_code: 41800 | ||
97 | + }, | ||
98 | + { | ||
99 | + sigun_name: '오산시', | ||
100 | + sigun_code: 41370 | ||
101 | + }, | ||
102 | + { | ||
103 | + sigun_name: '용인시', | ||
104 | + sigun_code: 41460 | ||
105 | + }, | ||
106 | + { | ||
107 | + sigun_name: '의왕시', | ||
108 | + sigun_code: 41430 | ||
109 | + }, | ||
110 | + { | ||
111 | + sigun_name: '의정부시', | ||
112 | + sigun_code: 41150 | ||
113 | + }, | ||
114 | + { | ||
115 | + sigun_name: '이천시', | ||
116 | + sigun_code: 41500 | ||
117 | + }, | ||
118 | + { | ||
119 | + sigun_name: '파주시', | ||
120 | + sigun_code: 41480 | ||
121 | + }, | ||
122 | + { | ||
123 | + sigun_name: '평택시', | ||
124 | + sigun_code: 41220 | ||
125 | + }, | ||
126 | + { | ||
127 | + sigun_name: '포천시', | ||
128 | + sigun_code: 41650 | ||
129 | + }, | ||
130 | + { | ||
131 | + sigun_name: '하남시', | ||
132 | + sigun_code: 41450 | ||
133 | + }, | ||
134 | + { | ||
135 | + sigun_name: '화성시', | ||
136 | + sigun_code: 41590 | ||
137 | + }, | ||
138 | +] | ||
139 | + | ||
9 | 140 | ||
10 | // 사용자가 index 페이지에서 주소를 입력하고 넘어오면 | 141 | // 사용자가 index 페이지에서 주소를 입력하고 넘어오면 |
11 | router.post('/', function(req, res) { | 142 | router.post('/', function(req, res) { |
12 | console.log(req.body); | 143 | console.log(req.body); |
13 | let userLocation = req.body.userLocation; | 144 | let userLocation = req.body.userLocation; |
14 | - // let userSi = req.body.si | 145 | + console.log('사용자가 입력한 주소', userLocation); |
15 | - // let userDong = req.body.dong; | ||
16 | - let user_latitude; | ||
17 | - let user_logitude; | ||
18 | - console.log(userLocation); | ||
19 | let KAKAO_API_KEY = process.env.KAKAO_APIKEY; | 146 | let KAKAO_API_KEY = process.env.KAKAO_APIKEY; |
20 | let kakaoOptions = { | 147 | let kakaoOptions = { |
21 | - url: 'https://dapi.kakao.com/v2/local/search/address.json', | 148 | + url: 'https://dapi.kakao.com/v2/local/search/address.json', |
22 | - method: 'GET', | 149 | + method: 'GET', |
23 | - headers: { | 150 | + headers: { |
24 | - 'Authorization': `KakaoAK ${KAKAO_API_KEY}` | 151 | + 'Authorization': `KakaoAK ${KAKAO_API_KEY}` |
25 | - }, | 152 | + }, |
26 | - qs: { | 153 | + qs: { |
27 | - query: userLocation | 154 | + query: userLocation |
28 | - }, | 155 | + }, |
29 | - encoding: 'UTF-8', | 156 | + encoding: 'UTF-8', |
157 | + } | ||
158 | + // sigun code 받는 부분 | ||
159 | + for (var key in sigun) { | ||
160 | + if (userLocation.includes(sigun[key].sigun_name)) { | ||
161 | + console.log('hey!'); | ||
162 | + SIGUN_CODE = sigun[key].sigun_code; | ||
163 | + } | ||
164 | + console.log(sigun[key].sigun_name); | ||
30 | } | 165 | } |
166 | + console.log('SIGUN_CODE', SIGUN_CODE); | ||
31 | request(kakaoOptions, function(err, res, body) { | 167 | request(kakaoOptions, function(err, res, body) { |
32 | if (!err && res.statusCode == 200) { | 168 | if (!err && res.statusCode == 200) { |
33 | var result = JSON.parse(body); | 169 | var result = JSON.parse(body); |
34 | console.log('result', result); | 170 | console.log('result', result); |
35 | user_latitude = result.documents[0].address.x; | 171 | user_latitude = result.documents[0].address.x; |
36 | user_logitude = result.documents[0].address.y; | 172 | user_logitude = result.documents[0].address.y; |
37 | - console.log(user_latitude, user_logitude); | 173 | + console.log('위도, 경도', user_latitude, user_logitude); |
38 | } | 174 | } |
39 | }) | 175 | }) |
40 | res.render('category', { userLocation: req.body.userLocation }); | 176 | res.render('category', { userLocation: req.body.userLocation }); |
... | @@ -45,7 +181,7 @@ router.get('/food', function(req, res) { | ... | @@ -45,7 +181,7 @@ router.get('/food', function(req, res) { |
45 | 181 | ||
46 | // 맛집 리스트 조회 | 182 | // 맛집 리스트 조회 |
47 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; | 183 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; |
48 | - let sigun_cd = 41110; | 184 | + let sigun_cd = SIGUN_CODE; |
49 | let url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt'; | 185 | let url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt'; |
50 | let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}&Type=json`; | 186 | let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}&Type=json`; |
51 | 187 | ||
... | @@ -55,16 +191,16 @@ router.get('/food', function(req, res) { | ... | @@ -55,16 +191,16 @@ router.get('/food', function(req, res) { |
55 | }, function(err, response, body) { | 191 | }, function(err, response, body) { |
56 | if (!err && res.statusCode == 200) { | 192 | if (!err && res.statusCode == 200) { |
57 | let food_result = JSON.parse(body); | 193 | let food_result = JSON.parse(body); |
194 | + // console.log('food_result', food_result.PlaceThatDoATasteyFoodSt[1]); | ||
58 | let store_names = [] | 195 | let store_names = [] |
59 | - // console.log('정상출력여부', result) | 196 | + for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) { |
60 | - // console.log('총 출력 개수', result.PlaceThatDoATasteyFoodSt[0].head[0].list_total_count); | ||
61 | - for (let i = 0; i < 16; i++) { | ||
62 | // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR) | 197 | // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR) |
63 | store_name = food_result.PlaceThatDoATasteyFoodSt[1].row[i]; | 198 | store_name = food_result.PlaceThatDoATasteyFoodSt[1].row[i]; |
64 | console.log('store_name', store_name); | 199 | console.log('store_name', store_name); |
65 | store_names.push(store_name); | 200 | store_names.push(store_name); |
66 | } | 201 | } |
67 | - console.log('food_result', food_result) | 202 | + console.log('food_result', food_result); |
203 | + console.log('store_names', store_names); | ||
68 | res.render('result', { store_names: store_names }); | 204 | res.render('result', { store_names: store_names }); |
69 | } | 205 | } |
70 | }); | 206 | }); |
... | @@ -74,29 +210,28 @@ router.get('/school', function(req, res) { | ... | @@ -74,29 +210,28 @@ router.get('/school', function(req, res) { |
74 | }); | 210 | }); |
75 | router.get('/park', function(req, res) { | 211 | router.get('/park', function(req, res) { |
76 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; | 212 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; |
77 | - let sigun_cd = 41110; | 213 | + let sigun_cd = SIGUN_CODE; |
78 | let cityparknum = 0; | 214 | let cityparknum = 0; |
79 | let url = 'https://openapi.gg.go.kr/CityPark'; | 215 | let url = 'https://openapi.gg.go.kr/CityPark'; |
80 | let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}`; | 216 | let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}`; |
81 | request({ | 217 | request({ |
82 | - url: url + qs, | 218 | + url: url + qs, |
83 | - method: 'GET' | 219 | + method: 'GET' |
84 | - }, function(err, response, body) { | 220 | + }, function(err, response, body) { |
85 | - var park_result = JSON.parse(body); | 221 | + var park_result = JSON.parse(body); |
86 | - if (park_result.CityPark[0].head[1].RESULT.CODE == 'INFO-000') { | 222 | + if (park_result.CityPark[0].head[1].RESULT.CODE == 'INFO-000') { |
87 | - cityparknum = park_result.CityPark[0].head[0].list_total_count; | 223 | + cityparknum = park_result.CityPark[0].head[0].list_total_count; |
88 | - console.log(cityparknum + "개의 도시공원이 존재합니다."); | 224 | + console.log(cityparknum + "개의 도시공원이 존재합니다."); |
89 | - res.send(String(cityparknum) + "개의 도시공원이 존재합니다."); | 225 | + res.send(String(cityparknum) + "개의 도시공원이 존재합니다."); |
90 | - } else { | 226 | + } else { |
91 | - res.send("도시공원이 없습니다."); | 227 | + res.send("도시공원이 없습니다."); |
92 | - } | 228 | + } |
93 | - }) | 229 | + }) |
94 | - //res.send('This is park'); | ||
95 | }); | 230 | }); |
96 | 231 | ||
97 | router.get('/shop', function(req, res) { | 232 | router.get('/shop', function(req, res) { |
98 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; | 233 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; |
99 | - let sigun_cd = 41110; | 234 | + let sigun_cd = SIGUN_CODE; |
100 | let mallnum = 0; | 235 | let mallnum = 0; |
101 | let url = 'https://openapi.gg.go.kr/MrktStoreM'; | 236 | let url = 'https://openapi.gg.go.kr/MrktStoreM'; |
102 | let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}`; | 237 | let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}`; |
... | @@ -117,7 +252,7 @@ router.get('/shop', function(req, res) { | ... | @@ -117,7 +252,7 @@ router.get('/shop', function(req, res) { |
117 | 252 | ||
118 | router.get('/gym', function(req, res) { | 253 | router.get('/gym', function(req, res) { |
119 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; | 254 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; |
120 | - let sigun_cd = 41110; | 255 | + let sigun_cd = SIGUN_CODE; |
121 | let gymnum = 0; | 256 | let gymnum = 0; |
122 | let url = 'https://openapi.gg.go.kr/PhysicaFitnessTrainingPlace'; | 257 | let url = 'https://openapi.gg.go.kr/PhysicaFitnessTrainingPlace'; |
123 | let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}`; | 258 | let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}`; | ... | ... |
-
Please register or login to post a comment