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
1
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김시환
2022-11-30 22:55:27 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
beeb5c06a683a11b5618cc9c9459cdcca9eabb55
beeb5c06
1 parent
17bacaf1
Update sample.js
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
41 deletions
sample.js
sample.js
View file @
beeb5c0
const
express
=
require
(
'express'
);
const
app
=
express
();
var
request
=
require
(
'request'
);
const
got
=
require
(
'got'
);
const
fetch
=
require
(
'node-fetch'
)
Request
=
fetch
.
Request
//필요한 주소 정보 (data 형식 확정 x )
let
addresses
=
`{
const
addrJson
=
`{
"current_address" : { "address" : "현재 위치 주소", "x" : 127.1058342, "y" : 37.359708},
"number" : 2,
"hospital_data" :[
...
...
@@ -13,50 +10,45 @@ let addresses = `{
]
}`
const
addr
ess
=
JSON
.
parse
(
addresses
)
const
addr
Data
=
JSON
.
parse
(
addrJson
);
var
options
=
{
const
ID
=
'12rhzhzq7g'
;
const
KEY
=
'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI'
;
const
data
=
{
cur
:
addrData
[
"current_address"
],
dist
:
addrData
[
"hospital_data"
].
map
((
e
)
=>
{
return
{
x
:
e
.
x
,
y
:
e
.
y
}})
}
const
fetchAPI
=
async
()
=>
{
const
baseOption
=
{
'method'
:
'GET'
,
'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'
},
};
};
const
ID
=
'12rhzhzq7g'
;
const
KEY
=
'FhD45P91TxG2820MadrsiPOUjI6bQMJhddnHZIeI'
;
const
promiseList
=
data
.
dist
.
map
(
async
(
dist
,
idx
)
=>
{
const
url
=
`https://naveropenapi.apigw.ntruss.com/map-direction-15/v1/driving?start=
${
data
.
cur
.
x
}
,
${
data
.
cur
.
y
}
&goal=
${
dist
.
x
}
,
${
dist
.
y
}
&option=trafast`
;
async
function
direction
(
data
){
var
num
=
data
.
number
;
var
a
=
[]
for
(
let
i
=
0
;
i
<
num
;
i
++
){
a
.
push
(
'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'
)
}
console
.
log
(
a
)
const
PromiseList
=
a
.
map
(
async
(
e
)
=>
{
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'
;
options
.
url
=
_url
;
return
await
request
(
options
,
function
(
error
,
respose
){
console
.
log
(
"11111111111111111"
)
var
databody
=
JSON
.
parse
(
respose
.
body
);
if
(
databody
.
code
!=
1
){
console
.
log
(
"2222222222222222"
)
console
.
log
(
databody
)
var
distance
=
databody
.
route
.
trafast
[
0
].
summary
.
distance
/
1000
;
// km 단위
var
duration
=
databody
.
route
.
trafast
[
0
].
summary
.
duration
/
1000
/
60
;
// 분 단위dy
data
.
hospital_data
[
i
].
distance
=
distance
;
console
.
log
(
data
.
hospital_data
[
i
].
distance
)
data
.
hospital_data
[
i
].
duration
=
duration
;}
})
})
const
result
=
await
Promise
.
all
(
PromiseList
)
let
request
=
new
Request
(
url
,
baseOption
);
return
fetch
(
request
).
then
(
async
res
=>
{
const
data
=
await
res
.
json
();
const
distance
=
data
.
route
?.
trafast
[
0
].
summary
.
distance
;
const
duration
=
data
.
route
?.
trafast
[
0
].
summary
.
duration
;
addrData
[
"hospital_data"
][
idx
].
distance
=
distance
;
addrData
[
"hospital_data"
][
idx
].
duration
=
duration
;
});
})
Promise
.
all
(
promiseList
).
then
(()
=>
{
console
.
log
(
"fetch end"
);
console
.
log
(
addrData
);
});
}
console
.
log
(
result
)
return
result
}
console
.
log
(
direction
(
address
))
\ No newline at end of file
fetchAPI
();
\ No newline at end of file
...
...
Please
register
or
login
to post a comment