윤규리

getXY

...@@ -46,9 +46,46 @@ function selectAddress(addressArray, number) { ...@@ -46,9 +46,46 @@ 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 +
49 function getXY(hospitals, addNum) { 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 === "의료,건강 > 병원 > 종합병원") or (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 + }
79 + return hospitals_xy;
80 + /*
81 + hospitals_xy:
82 + .my_x, .my_y: user's coordinates (to some precision..)
83 + [i].name: name of ith hospital
84 + [i].x, [i].y: coordinates of ith hospital
85 +
86 + */
50 87
51 - AddressList = null; 88 + // for loop 다 돈 다음에 return하도록 수정해야함 (하실수 있는분?)
52 -
53 } 89 }
90 +
54 module.exports = {getAddress, getXY}; 91 module.exports = {getAddress, getXY};
...\ No newline at end of file ...\ No newline at end of file
......