category.js
1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var express = require('express');
var router = express.Router();
var request = require('request');
require('dotenv').config();
/* GET home page. */
let GU_CODE;
let ANIMAL_INFO_API_KEY = process.env.ANIMAL_API_KEY;
let user_gu;
let user_latitude;
let user_longitude;
user_gu = 강북구;
/*
http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03
?serviceKey=88dc66a7-9143-4af3-9f7b-098355b2c7f8&numOfRows=10&pageNo=1&keyword=동물병원
&where=강북구
System.out.println(Arrays.toString(hospitals));
*/
router.get('/hospital', function (req, res) {
let institute_url = 'http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03';
let qs = `?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=10&pageNo=2&keyword=동물병원
&where=${user_gu}`;
request({
url: institute_url + qs,
method: 'GET'
}, function (err, response, body) {
if (!err && res.statusCode == 200) {
let hospital_result = JSON.parse(body);
let hospitals = [];
for (let i = 0; i < hospital_result.hr[1].row.length; i++) {
hospital = hospital_result.hr[1].row[i];
if (userArea(hospital, 'REFINE_LOTNO_ADDR', user_target)) {
hospitals.push(hospital);
}
}
res.render('result', { category: 'hospital', userLocation: userLocation });
}
})
});
module.exports = router;