root

.3

Showing 1 changed file with 21 additions and 15 deletions
1 const express= require('express'); 1 const express= require('express');
2 const app = express(); 2 const app = express();
3 var request = require('request'); 3 var request = require('request');
4 +const got = require('got');
4 5
5 //필요한 주소 정보 (data 형식 확정 x ) 6 //필요한 주소 정보 (data 형식 확정 x )
6 -let addresses = { 7 +let addresses = `{
7 "current_address" : { "address" : "현재 위치 주소", "x" : 127.1058342, "y" : 37.359708}, 8 "current_address" : { "address" : "현재 위치 주소", "x" : 127.1058342, "y" : 37.359708},
8 - "number" : 10, 9 + "number" : 2,
9 "hospital_data" :[ 10 "hospital_data" :[
10 {"name" : "병원명", "address" : "병원 주소", "x" : 129.075986, "y" : 35.179470, "distance" : 0, "duration" : 0}, 11 {"name" : "병원명", "address" : "병원 주소", "x" : 129.075986, "y" : 35.179470, "distance" : 0, "duration" : 0},
11 {"name" : "병원명", "address" : "병원 주소", "x" : 127.1058342, "y" : 37.359708, "distance" : 0, "duration" : 0} 12 {"name" : "병원명", "address" : "병원 주소", "x" : 127.1058342, "y" : 37.359708, "distance" : 0, "duration" : 0}
12 ] 13 ]
13 -} 14 +}`
15 +
16 +const address = JSON.parse(addresses)
14 17
15 var options = { 18 var options = {
16 'method': 'GET', 19 'method': 'GET',
...@@ -19,7 +22,7 @@ var options = { ...@@ -19,7 +22,7 @@ var options = {
19 'headers': { 22 'headers': {
20 'X-NCP-APIGW-API-KEY-ID': '12rhzhzq7g', 23 'X-NCP-APIGW-API-KEY-ID': '12rhzhzq7g',
21 'X-NCP-APIGW-API-KEY': 'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI' 24 'X-NCP-APIGW-API-KEY': 'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI'
22 - } 25 + },
23 }; 26 };
24 27
25 const ID = '12rhzhzq7g'; 28 const ID = '12rhzhzq7g';
...@@ -28,17 +31,20 @@ const KEY = 'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI'; ...@@ -28,17 +31,20 @@ const KEY = 'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI';
28 function direction(data){ 31 function direction(data){
29 var num = data.number; 32 var num = data.number;
30 for (let i = 0; i< num;i++){ 33 for (let i = 0; i< num;i++){
31 - const _url = 'https://naveropenapi.apigw.ntruss.com/map-direction-15/v1/driving?start='+data.current_address.x+','+data.current_address.y+'&goal='+data.hospital_data[i].x+','+data.hospital_data[i].y+'&option=trafast'; 34 + const _url = 'https://naveropenapi.apigw.ntruss.com/map-direction-15/v1/driving?start='+data.current_address.x+','+data.current_address.y+'&goal='+data.hospital_data[i].x+','+data.hospital_data[i].y+'&option=trafast';
32 - options.url = _url; 35 + options.url = _url;
33 - 36 + request(options,function(error, respose){
34 - request(options,function(error, respose){ 37 + var databody = JSON.parse(respose.body);
35 - var databody = JSON.parse(respose.body); 38 + if (databody.code !=1){
36 - var distance = databody.route.trafast[0].summary.distance/1000; // km 단위 39 + console.log(databody)
37 - var duration = databody.route.trafast[0].summary.duration/1000/60; // 분 단위dy 40 + var distance = databody.route.trafast[0].summary.distance/1000; // km 단위
38 - data.hospital_data[count].distance = distance; 41 + var duration = databody.route.trafast[0].summary.duration/1000/60; // 분 단위dy
39 - data.hospital_data[count].duration = duration; 42 + data.hospital_data[i].distance = distance;
40 - } 43 + data.hospital_data[i].duration = duration;}
41 - ) 44 + })
42 } 45 }
46 +
47 +
48 + console.log("TTTTTTTTTTTTT")
43 return data} 49 return data}
44 console.log(direction(address)) 50 console.log(direction(address))
...\ No newline at end of file ...\ No newline at end of file
......