홍예림

sample

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