Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김대연
/
emergency_room_ChatBot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
홍예림
2022-11-23 23:26:24 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
63291825bbc15959c944dd36cf1e1128267b8eb3
63291825
1 parent
ad494c7f
Directions_15_sample2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
2 deletions
Directions_15_sample.js
Directions_15_sample.js
View file @
6329182
var
request
=
require
(
'request'
);
//필요한 주소 정보 (data 형식 확정 x )
let
address
=
{
"current_address"
:
{
"address"
:
"현재 위치 주소"
,
"x"
:
127.1058342
,
"y"
:
37.359708
},
"number"
:
10
,
"hospital_data"
:[
{
"name"
:
"병원명"
,
"address"
:
"병원 주소"
,
"x"
:
129.075986
,
"y"
:
35.179470
},
{
"name"
:
"병원명"
,
"address"
:
"병원 주소"
,
"x"
:
127.1058342
,
"y"
:
37.359708
}
]
}
var
options
=
{
'method'
:
'GET'
,
'url'
:
'https://naveropenapi.apigw.ntruss.com/map-direction-15/v1/driving?start=127.1058342,37.359708&goal=129.075986,35.179470&option=trafast'
,
'url'
:
'https://naveropenapi.apigw.ntruss.com/map-direction-15/v1/driving?start='
+
address
.
current_address
.
x
+
','
+
address
.
current_address
.
y
+
'&goal='
+
address
.
hospital_data
[
0
].
x
+
','
+
address
.
hospital_data
[
0
].
y
+
'&option=trafast'
,
'headers'
:
{
'X-NCP-APIGW-API-KEY-ID'
:
'12rhzhzq7g'
,
'X-NCP-APIGW-API-KEY'
:
'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI'
}
};
request
(
options
,
function
(
error
,
response
)
{
if
(
error
)
throw
new
Error
(
error
);
console
.
log
(
response
.
body
);
let
body
=
JSON
.
parse
(
response
.
body
);
var
distance
=
body
.
route
.
trafast
[
0
].
summary
.
distance
/
1000
;
// km 단위
var
duration
=
body
.
route
.
trafast
[
0
].
summary
.
duration
/
1000
/
60
;
// 분 단위
const
data
=
{
"distance"
:
distance
,
"duration"
:
duration
}
console
.
log
(
data
);
});
//duration으로 정렬
function
durationSort
(
a
,
b
)
{
if
(
a
.
x
==
b
.
x
){
return
0
}
return
a
.
x
>
b
.
x
?
1
:
-
1
;
}
address
.
hospital_data
.
sort
(
durationSort
);
console
.
log
(
address
);
/*
최종 데이터 형식
{
"current_address" : { "address" : "현재 위치 주소", "x" : 127.1058342, "y" : 37.359708},
"number" : 10,
"hospital_data" :[
{"name" : "병원명", "address" : "병원 주소", "x" : 129.075986, "y" : 35.179470, "distance" : 377830, "duration" : 15177133},
{"name" : "병원명", "address" : "병원 주소", "x" : 127.1058342, "y" : 37.359708, "distance" : 377830, "duration" : 15177133}
]
}*/
...
...
Please
register
or
login
to post a comment