Showing
3 changed files
with
37 additions
and
24 deletions
... | @@ -6,6 +6,10 @@ require('dotenv').config(); | ... | @@ -6,6 +6,10 @@ require('dotenv').config(); |
6 | /* GET home page. */ | 6 | /* GET home page. */ |
7 | let SIGUN_CODE; | 7 | let SIGUN_CODE; |
8 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; | 8 | let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY; |
9 | +let user_sigun; | ||
10 | +let user_gu; | ||
11 | +let user_dong; | ||
12 | +let userLocation; | ||
9 | let user_latitude; | 13 | let user_latitude; |
10 | let user_logitude; | 14 | let user_logitude; |
11 | let sigun = [{ | 15 | let sigun = [{ |
... | @@ -142,8 +146,13 @@ let sigun = [{ | ... | @@ -142,8 +146,13 @@ let sigun = [{ |
142 | // 사용자가 index 페이지에서 주소를 입력하고 넘어오면 | 146 | // 사용자가 index 페이지에서 주소를 입력하고 넘어오면 |
143 | router.post('/', function(req, res) { | 147 | router.post('/', function(req, res) { |
144 | console.log(req.body); | 148 | console.log(req.body); |
145 | - let userLocation = req.body.userLocation; | 149 | + user_sigun = req.body.sigun; |
146 | - console.log('사용자가 입력한 주소', userLocation); | 150 | + user_gu = req.body.gu; |
151 | + user_dong = req.body.dong; | ||
152 | + userLocation = `${user_sigun} ${user_gu} ${user_dong}`; | ||
153 | + console.log(user_sigun); | ||
154 | + console.log(user_gu); | ||
155 | + console.log(user_dong); | ||
147 | let KAKAO_API_KEY = process.env.KAKAO_APIKEY; | 156 | let KAKAO_API_KEY = process.env.KAKAO_APIKEY; |
148 | let kakaoOptions = { | 157 | let kakaoOptions = { |
149 | url: 'https://dapi.kakao.com/v2/local/search/address.json', | 158 | url: 'https://dapi.kakao.com/v2/local/search/address.json', |
... | @@ -174,49 +183,51 @@ router.post('/', function(req, res) { | ... | @@ -174,49 +183,51 @@ router.post('/', function(req, res) { |
174 | console.log('위도, 경도', user_latitude, user_logitude); | 183 | console.log('위도, 경도', user_latitude, user_logitude); |
175 | } | 184 | } |
176 | }) | 185 | }) |
177 | - res.render('category', { userLocation: req.body.userLocation }); | 186 | + res.render('category', { userLocation: userLocation }); |
178 | }); | 187 | }); |
179 | 188 | ||
180 | 189 | ||
181 | router.get('/food', function(req, res) { | 190 | router.get('/food', function(req, res) { |
182 | 191 | ||
183 | // 맛집 리스트 조회 | 192 | // 맛집 리스트 조회 |
184 | - let url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt'; | 193 | + let food_url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt'; |
185 | let fastfood_url = 'https://openapi.gg.go.kr/Genrestrtfastfood' | 194 | let fastfood_url = 'https://openapi.gg.go.kr/Genrestrtfastfood' |
186 | let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}&Type=json`; | 195 | let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}&Type=json`; |
187 | 196 | ||
188 | request({ | 197 | request({ |
189 | - url: url + qs, | 198 | + url: food_url + qs, |
190 | method: 'GET' | 199 | method: 'GET' |
191 | }, function(err, response, body) { | 200 | }, function(err, response, body) { |
192 | if (!err && res.statusCode == 200) { | 201 | if (!err && res.statusCode == 200) { |
193 | let food_result = JSON.parse(body); | 202 | let food_result = JSON.parse(body); |
194 | // console.log('food_result', food_result.PlaceThatDoATasteyFoodSt[1]); | 203 | // console.log('food_result', food_result.PlaceThatDoATasteyFoodSt[1]); |
195 | - let store_names = []; | 204 | + let stores = []; |
196 | for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) { | 205 | for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) { |
197 | // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR) | 206 | // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR) |
198 | - store_name = food_result.PlaceThatDoATasteyFoodSt[1].row[i]; | 207 | + store = food_result.PlaceThatDoATasteyFoodSt[1].row[i]; |
199 | - console.log('store_name', store_name); | 208 | + if (store['REFINE_LOTNO_ADDR'].includes(user_dong)) { |
200 | - store_names.push(store_name); | 209 | + console.log('store', store); |
210 | + stores.push(store); | ||
211 | + } | ||
201 | } | 212 | } |
202 | console.log('food_result', food_result); | 213 | console.log('food_result', food_result); |
203 | - console.log('store_names', store_names); | 214 | + console.log('stores', stores); |
204 | request({ | 215 | request({ |
205 | url: fastfood_url + qs, | 216 | url: fastfood_url + qs, |
206 | method: 'GET' | 217 | method: 'GET' |
207 | }, function(err, response, body) { | 218 | }, function(err, response, body) { |
208 | if (!err && res.statusCode == 200) { | 219 | if (!err && res.statusCode == 200) { |
209 | let fast_food_result = JSON.parse(body); | 220 | let fast_food_result = JSON.parse(body); |
210 | - let fast_store_names = []; | 221 | + let fast_food_stores = []; |
211 | for (let i = 0; i < fast_food_result.Genrestrtfastfood[1].row.length; i++) { | 222 | for (let i = 0; i < fast_food_result.Genrestrtfastfood[1].row.length; i++) { |
212 | - fast_store_name = fast_food_result.Genrestrtfastfood[1].row[i]; | 223 | + fast_food_store = fast_food_result.Genrestrtfastfood[1].row[i]; |
213 | // 폐업인 지점 제외 | 224 | // 폐업인 지점 제외 |
214 | - if (fast_store_name['BSN_STATE_NM'] != '폐업') { | 225 | + if (fast_food_store['BSN_STATE_NM'] != '폐업' && fast_food_store['REFINE_LOTNO_ADDR'].includes(user_dong)) { |
215 | - console.log('fast_store_name', fast_store_name); | 226 | + console.log('fast_store_name', fast_food_store); |
216 | - fast_store_names.push(fast_store_name); | 227 | + fast_food_stores.push(fast_food_store); |
217 | } | 228 | } |
218 | } | 229 | } |
219 | - res.render('food_result', { store_names: store_names, fast_store_names: fast_store_names }); | 230 | + res.render('food_result', { stores: stores, fast_food_stores: fast_food_stores }); |
220 | } | 231 | } |
221 | 232 | ||
222 | }) | 233 | }) |
... | @@ -294,7 +305,7 @@ router.get('/park', function(req, res) { | ... | @@ -294,7 +305,7 @@ router.get('/park', function(req, res) { |
294 | }); | 305 | }); |
295 | 306 | ||
296 | router.get('/transport', function(req, res) { | 307 | router.get('/transport', function(req, res) { |
297 | - res.send(BusCnt); | 308 | + let |
298 | }); | 309 | }); |
299 | router.get('/safe', function(req, res) { | 310 | router.get('/safe', function(req, res) { |
300 | 311 | ... | ... |
... | @@ -8,24 +8,24 @@ | ... | @@ -8,24 +8,24 @@ |
8 | 8 | ||
9 | <body> | 9 | <body> |
10 | <h1>🥘 맛집 현황 </h1> | 10 | <h1>🥘 맛집 현황 </h1> |
11 | - <%for (var i =0; i <store_names.length; i++){%> | 11 | + <%for (var i =0; i <stores.length; i++){%> |
12 | <li> | 12 | <li> |
13 | - <%=store_names[i].RESTRT_NM%> | 13 | + <%=stores[i].RESTRT_NM%> |
14 | </li> | 14 | </li> |
15 | 15 | ||
16 | <%}%> | 16 | <%}%> |
17 | <h3>총 맛집 개수 : | 17 | <h3>총 맛집 개수 : |
18 | - <%=store_names.length%> | 18 | + <%=stores.length%> |
19 | </h3> | 19 | </h3> |
20 | <h1>🍔 패스트푸드점 현황 </h1> | 20 | <h1>🍔 패스트푸드점 현황 </h1> |
21 | - <%for (var i =0; i <fast_store_names.length; i++){%> | 21 | + <%for (var i =0; i <fast_food_stores.length; i++){%> |
22 | <li> | 22 | <li> |
23 | - <%=fast_store_names[i].BIZPLC_NM%> | 23 | + <%=fast_food_stores[i].BIZPLC_NM%> |
24 | </li> | 24 | </li> |
25 | 25 | ||
26 | <%}%> | 26 | <%}%> |
27 | <h3>패스트푸드점 개수 : | 27 | <h3>패스트푸드점 개수 : |
28 | - <%=fast_store_names.length%> | 28 | + <%=fast_food_stores.length%> |
29 | </h3> | 29 | </h3> |
30 | 30 | ||
31 | </body> | 31 | </body> | ... | ... |
... | @@ -19,7 +19,9 @@ | ... | @@ -19,7 +19,9 @@ |
19 | <input type="submit" id="search" value="검색"> --> | 19 | <input type="submit" id="search" value="검색"> --> |
20 | <div class="form-group"> | 20 | <div class="form-group"> |
21 | <label for="exampleFormControlInput1">당신이 조사하고 싶은 동네의 주소를 입력하세요!</label> | 21 | <label for="exampleFormControlInput1">당신이 조사하고 싶은 동네의 주소를 입력하세요!</label> |
22 | - <input type="text" class="form-control" id="exampleFormControlInput1" name="userLocation" placeholder="당신의 동네 주소를 입력해주세요(시/구/동)"> | 22 | + <input type="text" class="form-control" id="exampleFormControlInput1" name="sigun" placeholder="시/군을 입력하세요"> |
23 | + <input type="text" class="form-control" id="exampleFormControlInput1" name="gu" placeholder="구를 입력하세요"> | ||
24 | + <input type="text" class="form-control" id="exampleFormControlInput1" name="dong" placeholder="읍/면/동을 입력하세요"> | ||
23 | </div> | 25 | </div> |
24 | <button type="submit" class="btn btn-primary">검색</button> | 26 | <button type="submit" class="btn btn-primary">검색</button> |
25 | </form> | 27 | </form> | ... | ... |
-
Please register or login to post a comment