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 04:25:36 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9363f32ee3cbfd612c136c97e4b746a09e7f7af2
9363f32e
1 parent
a807c874
Add dynamic sigun_code update
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
172 additions
and
37 deletions
routes/category.js
routes/category.js
View file @
9363f32
...
...
@@ -5,36 +5,172 @@ require('dotenv').config();
/* GET home page. */
let
SIGUN_CODE
;
let
SIGUNDONG_CODE
;
let
user_latitude
;
let
user_logitude
;
let
sigun
=
[{
sigun_name
:
'가평군'
,
sigun_code
:
41820
},
{
sigun_name
:
'경기도'
,
sigun_code
:
41000
},
{
sigun_name
:
'고양시'
,
sigun_code
:
41280
},
{
sigun_name
:
'과천시'
,
sigun_code
:
41290
},
{
sigun_name
:
'광명시'
,
sigun_code
:
41210
},
{
sigun_name
:
'광주시'
,
sigun_code
:
41610
},
{
sigun_name
:
'구리시'
,
sigun_code
:
41310
},
{
sigun_name
:
'군포시'
,
sigun_code
:
41410
},
{
sigun_name
:
'김포시'
,
sigun_code
:
41570
},
{
sigun_name
:
'남양주시'
,
sigun_code
:
41360
},
{
sigun_name
:
'동두천시'
,
sigun_code
:
41250
},
{
sigun_name
:
'부천시'
,
sigun_code
:
41190
},
{
sigun_name
:
'성남시'
,
sigun_code
:
41130
},
{
sigun_name
:
'수원시'
,
sigun_code
:
41110
},
{
sigun_name
:
'시흥시'
,
sigun_code
:
41390
},
{
sigun_name
:
'안산시'
,
sigun_code
:
41270
},
{
sigun_name
:
'안성시'
,
sigun_code
:
41550
},
{
sigun_name
:
'안양시'
,
sigun_code
:
41170
},
{
sigun_name
:
'양주시'
,
sigun_code
:
41630
},
{
sigun_name
:
'양평군'
,
sigun_code
:
41830
},
{
sigun_name
:
'여주시'
,
sigun_code
:
41670
},
{
sigun_name
:
'연천군'
,
sigun_code
:
41800
},
{
sigun_name
:
'오산시'
,
sigun_code
:
41370
},
{
sigun_name
:
'용인시'
,
sigun_code
:
41460
},
{
sigun_name
:
'의왕시'
,
sigun_code
:
41430
},
{
sigun_name
:
'의정부시'
,
sigun_code
:
41150
},
{
sigun_name
:
'이천시'
,
sigun_code
:
41500
},
{
sigun_name
:
'파주시'
,
sigun_code
:
41480
},
{
sigun_name
:
'평택시'
,
sigun_code
:
41220
},
{
sigun_name
:
'포천시'
,
sigun_code
:
41650
},
{
sigun_name
:
'하남시'
,
sigun_code
:
41450
},
{
sigun_name
:
'화성시'
,
sigun_code
:
41590
},
]
// 사용자가 index 페이지에서 주소를 입력하고 넘어오면
router
.
post
(
'/'
,
function
(
req
,
res
)
{
console
.
log
(
req
.
body
);
let
userLocation
=
req
.
body
.
userLocation
;
// let userSi = req.body.si
// let userDong = req.body.dong;
let
user_latitude
;
let
user_logitude
;
console
.
log
(
userLocation
);
console
.
log
(
'사용자가 입력한 주소'
,
userLocation
);
let
KAKAO_API_KEY
=
process
.
env
.
KAKAO_APIKEY
;
let
kakaoOptions
=
{
url
:
'https://dapi.kakao.com/v2/local/search/address.json'
,
method
:
'GET'
,
headers
:
{
'Authorization'
:
`KakaoAK
${
KAKAO_API_KEY
}
`
},
qs
:
{
query
:
userLocation
},
encoding
:
'UTF-8'
,
url
:
'https://dapi.kakao.com/v2/local/search/address.json'
,
method
:
'GET'
,
headers
:
{
'Authorization'
:
`KakaoAK
${
KAKAO_API_KEY
}
`
},
qs
:
{
query
:
userLocation
},
encoding
:
'UTF-8'
,
}
// sigun code 받는 부분
for
(
var
key
in
sigun
)
{
if
(
userLocation
.
includes
(
sigun
[
key
].
sigun_name
))
{
console
.
log
(
'hey!'
);
SIGUN_CODE
=
sigun
[
key
].
sigun_code
;
}
console
.
log
(
sigun
[
key
].
sigun_name
);
}
console
.
log
(
'SIGUN_CODE'
,
SIGUN_CODE
);
request
(
kakaoOptions
,
function
(
err
,
res
,
body
)
{
if
(
!
err
&&
res
.
statusCode
==
200
)
{
var
result
=
JSON
.
parse
(
body
);
console
.
log
(
'result'
,
result
);
user_latitude
=
result
.
documents
[
0
].
address
.
x
;
user_logitude
=
result
.
documents
[
0
].
address
.
y
;
console
.
log
(
user_latitude
,
user_logitude
);
console
.
log
(
'위도, 경도'
,
user_latitude
,
user_logitude
);
}
})
res
.
render
(
'category'
,
{
userLocation
:
req
.
body
.
userLocation
});
...
...
@@ -45,7 +181,7 @@ router.get('/food', function(req, res) {
// 맛집 리스트 조회
let
GYEONGI_API_KEY
=
process
.
env
.
GYEONGGI_APIKEY
;
let
sigun_cd
=
41110
;
let
sigun_cd
=
SIGUN_CODE
;
let
url
=
'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt'
;
let
qs
=
`?KEY=
${
GYEONGI_API_KEY
}
&SIGUN_CD=
${
sigun_cd
}
&Type=json`
;
...
...
@@ -55,16 +191,16 @@ router.get('/food', function(req, res) {
},
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_names
=
[]
// console.log('정상출력여부', result)
// console.log('총 출력 개수', result.PlaceThatDoATasteyFoodSt[0].head[0].list_total_count);
for
(
let
i
=
0
;
i
<
16
;
i
++
)
{
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
);
}
console
.
log
(
'food_result'
,
food_result
)
console
.
log
(
'food_result'
,
food_result
);
console
.
log
(
'store_names'
,
store_names
);
res
.
render
(
'result'
,
{
store_names
:
store_names
});
}
});
...
...
@@ -74,29 +210,28 @@ router.get('/school', function(req, res) {
});
router
.
get
(
'/park'
,
function
(
req
,
res
)
{
let
GYEONGI_API_KEY
=
process
.
env
.
GYEONGGI_APIKEY
;
let
sigun_cd
=
41110
;
let
sigun_cd
=
SIGUN_CODE
;
let
cityparknum
=
0
;
let
url
=
'https://openapi.gg.go.kr/CityPark'
;
let
qs
=
`?Type=json&KEY=
${
GYEONGI_API_KEY
}
&SIGUN_CD=
${
sigun_cd
}
`
;
request
({
url
:
url
+
qs
,
method
:
'GET'
},
function
(
err
,
response
,
body
)
{
var
park_result
=
JSON
.
parse
(
body
);
if
(
park_result
.
CityPark
[
0
].
head
[
1
].
RESULT
.
CODE
==
'INFO-000'
)
{
cityparknum
=
park_result
.
CityPark
[
0
].
head
[
0
].
list_total_count
;
console
.
log
(
cityparknum
+
"개의 도시공원이 존재합니다."
);
res
.
send
(
String
(
cityparknum
)
+
"개의 도시공원이 존재합니다."
);
}
else
{
res
.
send
(
"도시공원이 없습니다."
);
}
})
//res.send('This is park');
url
:
url
+
qs
,
method
:
'GET'
},
function
(
err
,
response
,
body
)
{
var
park_result
=
JSON
.
parse
(
body
);
if
(
park_result
.
CityPark
[
0
].
head
[
1
].
RESULT
.
CODE
==
'INFO-000'
)
{
cityparknum
=
park_result
.
CityPark
[
0
].
head
[
0
].
list_total_count
;
console
.
log
(
cityparknum
+
"개의 도시공원이 존재합니다."
);
res
.
send
(
String
(
cityparknum
)
+
"개의 도시공원이 존재합니다."
);
}
else
{
res
.
send
(
"도시공원이 없습니다."
);
}
})
});
router
.
get
(
'/shop'
,
function
(
req
,
res
)
{
let
GYEONGI_API_KEY
=
process
.
env
.
GYEONGGI_APIKEY
;
let
sigun_cd
=
41110
;
let
sigun_cd
=
SIGUN_CODE
;
let
mallnum
=
0
;
let
url
=
'https://openapi.gg.go.kr/MrktStoreM'
;
let
qs
=
`?Type=json&KEY=
${
GYEONGI_API_KEY
}
&SIGUN_CD=
${
sigun_cd
}
`
;
...
...
@@ -117,7 +252,7 @@ router.get('/shop', function(req, res) {
router
.
get
(
'/gym'
,
function
(
req
,
res
)
{
let
GYEONGI_API_KEY
=
process
.
env
.
GYEONGGI_APIKEY
;
let
sigun_cd
=
41110
;
let
sigun_cd
=
SIGUN_CODE
;
let
gymnum
=
0
;
let
url
=
'https://openapi.gg.go.kr/PhysicaFitnessTrainingPlace'
;
let
qs
=
`?Type=json&KEY=
${
GYEONGI_API_KEY
}
&SIGUN_CD=
${
sigun_cd
}
`
;
...
...
Please
register
or
login
to post a comment