Merge branch 'main' into 'main'
misc. + getXY See merge request !7
Showing
1 changed file
with
40 additions
and
2 deletions
... | @@ -46,9 +46,47 @@ function selectAddress(addressArray, number) { | ... | @@ -46,9 +46,47 @@ function selectAddress(addressArray, number) { |
46 | 46 | ||
47 | // hospitals: array from hospital API | 47 | // hospitals: array from hospital API |
48 | // addNum: index of addressArray | 48 | // addNum: index of addressArray |
49 | -function getXY(hospitals, addNum) { | ||
50 | 49 | ||
50 | +function getXY(hospitals, addNum) { | ||
51 | + var hospitals_xy = new Array(); | ||
52 | + hospitals_xy.my_x = AddressList[addNum].road_address.x; | ||
53 | + hospitals_xy.my_y = AddressList[addNum].road_address.y; | ||
54 | + // hopsitals_keyword[i] : name, x, y | ||
55 | + | ||
56 | + for (let i = 0; i < hospitals.length; i++) { // iterate through available hospitals... | ||
57 | + | ||
58 | + fetch('https://dapi.kakao.com/v2/local/search/keyword.json?' + new URLSearchParams({ | ||
59 | + query: hospitals.name, | ||
60 | + category_group_code: "HP8" | ||
61 | + }), { | ||
62 | + method: "GET", | ||
63 | + headers: {"Authorization": "KakaoAK c14234ba46c574c73715276c5644f397"} | ||
64 | + }) | ||
65 | + .then(response => response.json()) | ||
66 | + .then(data => { | ||
67 | + for (let j = 0; j < data.length; j++) { | ||
68 | + if ((data.documents[j].category_name === "의료,건강 > 병원 > 종합병원") || (data.documents[j].category_name === "의료,건강 > 병원 > 대학병원")) { | ||
69 | + hospitals_xy[i].name = data.documents[j].place_name; | ||
70 | + hospitals_xy[i].x = data.documents[j].x; | ||
71 | + hospitals_xy[i].y = data.documents[j].y; | ||
72 | + break; | ||
73 | + } | ||
74 | + } | ||
75 | + | ||
76 | + }) | ||
77 | + | ||
78 | + } | ||
51 | AddressList = null; | 79 | AddressList = null; |
52 | - | 80 | + return hospitals_xy; |
81 | + /* | ||
82 | + hospitals_xy: | ||
83 | + .my_x, .my_y: user's coordinates (to some precision..) | ||
84 | + [i].name: name of ith hospital | ||
85 | + [i].x, [i].y: coordinates of ith hospital | ||
86 | + | ||
87 | + */ | ||
88 | + | ||
89 | + // for loop 다 돈 다음에 return하도록 수정해야함 (하실수 있는분?) | ||
53 | } | 90 | } |
91 | + | ||
54 | module.exports = {getAddress, getXY}; | 92 | module.exports = {getAddress, getXY}; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment