-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDirections_15_sample_app.js
38 lines (34 loc) · 1.39 KB
/
Directions_15_sample_app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const express= require('express');
const app = express();
const request = require('request')
require("dotenv").config( {path: "/home/ec2-user/prj/emergency_room_ChatBot/.env"} );
const ID = process.env.DIR_ID;
const KEY = process.env.DIR_KEY;
app.post('/direction',function(req,res){
let data_body = req.body;
var num = data_body.number;
let count = 0;
while (count<num){
const _url = 'https://naveropenapi.apigw.ntruss.com/map-direction-15/v1/driving?start='+data_body.address.current_address.x+','
+data_body.address.current_address.y+'&goal='+data_body.hospital_data[count].x+','+data_body.hospital_data[count].y+'&option=trafast';
}
request.post(
{
method : 'GET',
url : _url,
headers : {
'X-NCP-APIGW-API-KEY-ID': ID,
'X-NCP-APIGW-API-KEY': KEY
}
},(error, res, body) => {
let body = JSON.parse(res.body);
var distance = body.route.trafast[0].summary.distance/1000; // km 단위
var duration = body.route.trafast[0].summary.duration/1000/60; // 분 단위dy
data_body.hospital_data[count].distance = distance;
data_body.hospital_data[count].duration = duration;
}
);
count += 1;
res.send(data_body)
}
)