김시환

Merge branch 'Yerim' into 'main'

Yerim



See merge request !8
1 var request = require('request'); 1 var request = require('request');
2 +
3 +//필요한 주소 정보 (data 형식 확정 x )
4 +let address = {
5 + "current_address" : { "address" : "현재 위치 주소", "x" : 127.1058342, "y" : 37.359708},
6 + "number" : 10,
7 + "hospital_data" :[
8 + {"name" : "병원명", "address" : "병원 주소", "x" : 129.075986, "y" : 35.179470},
9 + {"name" : "병원명", "address" : "병원 주소", "x" : 127.1058342, "y" : 37.359708}
10 + ]
11 +}
12 +
13 +
2 var options = { 14 var options = {
3 'method': 'GET', 15 'method': 'GET',
4 - 'url': 'https://naveropenapi.apigw.ntruss.com/map-direction-15/v1/driving?start=127.1058342,37.359708&goal=129.075986,35.179470&option=trafast', 16 + 'url': 'https://naveropenapi.apigw.ntruss.com/map-direction-15/v1/driving?start='+address.current_address.x+','
17 + +address.current_address.y+'&goal='+address.hospital_data[0].x+','+address.hospital_data[0].y+'&option=trafast',
5 'headers': { 18 'headers': {
6 'X-NCP-APIGW-API-KEY-ID': '12rhzhzq7g', 19 'X-NCP-APIGW-API-KEY-ID': '12rhzhzq7g',
7 'X-NCP-APIGW-API-KEY': 'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI' 20 'X-NCP-APIGW-API-KEY': 'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI'
8 } 21 }
9 }; 22 };
23 +
10 request(options, function (error, response) { 24 request(options, function (error, response) {
11 if (error) throw new Error(error); 25 if (error) throw new Error(error);
12 - console.log(response.body); 26 + let body = JSON.parse(response.body);
27 + var distance = body.route.trafast[0].summary.distance/1000; // km 단위
28 + var duration = body.route.trafast[0].summary.duration/1000/60; // 분 단위
29 + const data = {
30 + "distance" : distance,
31 + "duration" : duration
32 + }
33 + console.log(data);
13 }); 34 });
35 +
36 +
37 +//duration으로 정렬
38 +function durationSort(a, b) {
39 + if(a.x == b.x){ return 0} return a.x > b.x ? 1 : -1;
40 +}
41 +address.hospital_data.sort(durationSort);
42 +console.log(address);
43 +
44 +
45 +
46 +/*
47 +최종 데이터 형식
48 +{
49 + "current_address" : { "address" : "현재 위치 주소", "x" : 127.1058342, "y" : 37.359708},
50 + "number" : 10,
51 + "hospital_data" :[
52 + {"name" : "병원명", "address" : "병원 주소", "x" : 129.075986, "y" : 35.179470, "distance" : 377830, "duration" : 15177133},
53 + {"name" : "병원명", "address" : "병원 주소", "x" : 127.1058342, "y" : 37.359708, "distance" : 377830, "duration" : 15177133}
54 + ]
55 +}*/
56 +
57 +
58 +
59 +
60 +
......
1 +{
2 + "current_address" : { "address" : "현재 위치 주소", "x" : 127.1058342, "y" : 37.359708},
3 + "number" : 10,
4 + "hospital_data" :[
5 + {"name" : "병원명", "address" : "병원 주소", "x" : 129.075986, "y" : 35.179470, "distance" : 377830, "duration" : 15177133},
6 + {"name" : "병원명", "address" : "병원 주소", "x" : 127.1058342, "y" : 37.359708, "distance" : 377830, "duration" : 15177133}
7 + ]
8 +}
9 +