홍예림

Directions_15_sample_app1

1 +const express= require('express');
2 +const app = express();
3 +const request = require('request')
4 +
5 +const ID = '12rhzhzq7g';
6 +const KEY = 'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI';
7 +
8 +app.post('/direction',function(req,res){
9 + let data_body = req.body;
10 + var num = data_body.number;
11 + let count = 0;
12 +
13 +
14 + while (count<num){
15 + const _url = 'https://naveropenapi.apigw.ntruss.com/map-direction-15/v1/driving?start='+data_body.address.current_address.x+','
16 + +data_body.address.current_address.y+'&goal='+data_body.hospital_data[count].x+','+data_body.hospital_data[count].y+'&option=trafast';
17 + }
18 + request.post(
19 + {
20 + method : 'GET',
21 + url : _url,
22 + headers : {
23 + 'X-NCP-APIGW-API-KEY-ID': ID,
24 + 'X-NCP-APIGW-API-KEY': KEY
25 + }
26 + },(error, res, body) => {
27 + let body = JSON.parse(res.body);
28 + var distance = body.route.trafast[0].summary.distance/1000; // km 단위
29 + var duration = body.route.trafast[0].summary.duration/1000/60; // 분 단위dy
30 + data_body.hospital_data[count].distance = distance;
31 + data_body.hospital_data[count].duration = duration;
32 + }
33 + );
34 + count += 1;
35 + res.send(data_body)
36 + }
37 +)