Toggle navigation
Toggle navigation
This project
Loading...
Sign in
zuzitsu
/
UR_Village
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Suyeon Jung
2020-12-07 16:00:53 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c4174e978df352853274178a34505b3265c10a41
c4174e97
1 parent
1aba41a8
Add dong condition to result and Add input box to index
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
24 deletions
routes/category.js
views/food_result.ejs
views/index.ejs
routes/category.js
View file @
c4174e9
...
...
@@ -6,6 +6,10 @@ require('dotenv').config();
/* GET home page. */
let
SIGUN_CODE
;
let
GYEONGI_API_KEY
=
process
.
env
.
GYEONGGI_APIKEY
;
let
user_sigun
;
let
user_gu
;
let
user_dong
;
let
userLocation
;
let
user_latitude
;
let
user_logitude
;
let
sigun
=
[{
...
...
@@ -142,8 +146,13 @@ let sigun = [{
// 사용자가 index 페이지에서 주소를 입력하고 넘어오면
router
.
post
(
'/'
,
function
(
req
,
res
)
{
console
.
log
(
req
.
body
);
let
userLocation
=
req
.
body
.
userLocation
;
console
.
log
(
'사용자가 입력한 주소'
,
userLocation
);
user_sigun
=
req
.
body
.
sigun
;
user_gu
=
req
.
body
.
gu
;
user_dong
=
req
.
body
.
dong
;
userLocation
=
`
${
user_sigun
}
${
user_gu
}
${
user_dong
}
`
;
console
.
log
(
user_sigun
);
console
.
log
(
user_gu
);
console
.
log
(
user_dong
);
let
KAKAO_API_KEY
=
process
.
env
.
KAKAO_APIKEY
;
let
kakaoOptions
=
{
url
:
'https://dapi.kakao.com/v2/local/search/address.json'
,
...
...
@@ -174,49 +183,51 @@ router.post('/', function(req, res) {
console
.
log
(
'위도, 경도'
,
user_latitude
,
user_logitude
);
}
})
res
.
render
(
'category'
,
{
userLocation
:
req
.
body
.
userLocation
});
res
.
render
(
'category'
,
{
userLocation
:
userLocation
});
});
router
.
get
(
'/food'
,
function
(
req
,
res
)
{
// 맛집 리스트 조회
let
url
=
'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt'
;
let
food_
url
=
'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt'
;
let
fastfood_url
=
'https://openapi.gg.go.kr/Genrestrtfastfood'
let
qs
=
`?KEY=
${
GYEONGI_API_KEY
}
&SIGUN_CD=
${
SIGUN_CODE
}
&Type=json`
;
request
({
url
:
url
+
qs
,
url
:
food_
url
+
qs
,
method
:
'GET'
},
function
(
err
,
response
,
body
)
{
if
(
!
err
&&
res
.
statusCode
==
200
)
{
let
food_result
=
JSON
.
parse
(
body
);
// console.log('food_result', food_result.PlaceThatDoATasteyFoodSt[1]);
let
store
_name
s
=
[];
let
stores
=
[];
for
(
let
i
=
0
;
i
<
food_result
.
PlaceThatDoATasteyFoodSt
[
1
].
row
.
length
;
i
++
)
{
// 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR)
store_name
=
food_result
.
PlaceThatDoATasteyFoodSt
[
1
].
row
[
i
];
console
.
log
(
'store_name'
,
store_name
);
store_names
.
push
(
store_name
);
store
=
food_result
.
PlaceThatDoATasteyFoodSt
[
1
].
row
[
i
];
if
(
store
[
'REFINE_LOTNO_ADDR'
].
includes
(
user_dong
))
{
console
.
log
(
'store'
,
store
);
stores
.
push
(
store
);
}
}
console
.
log
(
'food_result'
,
food_result
);
console
.
log
(
'store
_names'
,
store_nam
es
);
console
.
log
(
'store
s'
,
stor
es
);
request
({
url
:
fastfood_url
+
qs
,
method
:
'GET'
},
function
(
err
,
response
,
body
)
{
if
(
!
err
&&
res
.
statusCode
==
200
)
{
let
fast_food_result
=
JSON
.
parse
(
body
);
let
fast_
store_nam
es
=
[];
let
fast_
food_stor
es
=
[];
for
(
let
i
=
0
;
i
<
fast_food_result
.
Genrestrtfastfood
[
1
].
row
.
length
;
i
++
)
{
fast_
store_nam
e
=
fast_food_result
.
Genrestrtfastfood
[
1
].
row
[
i
];
fast_
food_stor
e
=
fast_food_result
.
Genrestrtfastfood
[
1
].
row
[
i
];
// 폐업인 지점 제외
if
(
fast_
store_name
[
'BSN_STATE_NM'
]
!=
'폐업'
)
{
console
.
log
(
'fast_store_name'
,
fast_
store_nam
e
);
fast_
store_names
.
push
(
fast_store_nam
e
);
if
(
fast_
food_store
[
'BSN_STATE_NM'
]
!=
'폐업'
&&
fast_food_store
[
'REFINE_LOTNO_ADDR'
].
includes
(
user_dong
)
)
{
console
.
log
(
'fast_store_name'
,
fast_
food_stor
e
);
fast_
food_stores
.
push
(
fast_food_stor
e
);
}
}
res
.
render
(
'food_result'
,
{
store
_names
:
store_names
,
fast_store_names
:
fast_store_nam
es
});
res
.
render
(
'food_result'
,
{
store
s
:
stores
,
fast_food_stores
:
fast_food_stor
es
});
}
})
...
...
@@ -294,7 +305,7 @@ router.get('/park', function(req, res) {
});
router
.
get
(
'/transport'
,
function
(
req
,
res
)
{
res
.
send
(
BusCnt
);
let
});
router
.
get
(
'/safe'
,
function
(
req
,
res
)
{
...
...
views/food_result.ejs
View file @
c4174e9
...
...
@@ -8,24 +8,24 @@
<body>
<h1>
🥘 맛집 현황
</h1>
<
%for (var i =0; i
<store
_name
s
.
length
;
i
++){%
>
<
%for (var i =0; i
<stores
.
length
;
i
++){%
>
<li>
<
%=store
_name
s[i].RESTRT_NM%>
<
%=stores[i].RESTRT_NM%>
</li>
<
%}%>
<h3>
총 맛집 개수 :
<
%=store
_name
s.length%>
<
%=stores.length%>
</h3>
<h1>
🍔 패스트푸드점 현황
</h1>
<
%for (var i =0; i
<fast
_
store_nam
es
.
length
;
i
++){%
>
<
%for (var i =0; i
<fast
_
food_stor
es
.
length
;
i
++){%
>
<li>
<
%=fast_
store_nam
es[i].BIZPLC_NM%>
<
%=fast_
food_stor
es[i].BIZPLC_NM%>
</li>
<
%}%>
<h3>
패스트푸드점 개수 :
<
%=fast_
store_nam
es.length%>
<
%=fast_
food_stor
es.length%>
</h3>
</body>
...
...
views/index.ejs
View file @
c4174e9
...
...
@@ -19,7 +19,9 @@
<input type="submit" id="search" value="검색"> -->
<div
class=
"form-group"
>
<label
for=
"exampleFormControlInput1"
>
당신이 조사하고 싶은 동네의 주소를 입력하세요!
</label>
<input
type=
"text"
class=
"form-control"
id=
"exampleFormControlInput1"
name=
"userLocation"
placeholder=
"당신의 동네 주소를 입력해주세요(시/구/동)"
>
<input
type=
"text"
class=
"form-control"
id=
"exampleFormControlInput1"
name=
"sigun"
placeholder=
"시/군을 입력하세요"
>
<input
type=
"text"
class=
"form-control"
id=
"exampleFormControlInput1"
name=
"gu"
placeholder=
"구를 입력하세요"
>
<input
type=
"text"
class=
"form-control"
id=
"exampleFormControlInput1"
name=
"dong"
placeholder=
"읍/면/동을 입력하세요"
>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
검색
</button>
</form>
...
...
Please
register
or
login
to post a comment