Toggle navigation
Toggle navigation
This project
Loading...
Sign in
권주희
/
howsTheAir
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
권주희
2020-06-23 15:08:51 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f5bd852bbec4ff54fe011fdc96b82331e8ec3afb
f5bd852b
1 parent
0d6b8629
implement get current weather api
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
backend/routes/airCondition.js
backend/routes/airCondition.js
View file @
f5bd852
...
...
@@ -4,6 +4,7 @@ var axios = require("axios");
const
openAPIKey
=
require
(
"./secrets.json"
).
openAPIKey
;
const
googleMapKey
=
require
(
"./secrets.json"
).
googleAPIKey
;
const
weatherAPIKey
=
require
(
"./secrets.json"
).
weatherAPIKey
;
axios
.
create
({
// TODO : 웹을 AWS에 올릴때, 해당 baseURL이 달라져야할 수 있음
...
...
@@ -25,6 +26,40 @@ router.get("/", async function (req, res, next) {
res
.
send
(
airCondition
);
});
router
.
get
(
"/weather"
,
async
function
(
req
,
res
,
next
)
{
console
.
log
(
"경도:"
,
req
.
query
.
latitude
);
console
.
log
(
"경도:"
,
req
.
query
.
longitude
);
let
airCondition
=
""
;
let
response
=
await
getEnglishPosition
(
req
.
query
.
latitude
,
req
.
query
.
longitude
)
.
then
((
encodedStation
)
=>
getWeather
(
encodedStation
))
.
then
((
result
)
=>
{
airCondition
=
result
;
});
res
.
send
(
airCondition
);
});
const
getWeather
=
(
encodedStation
)
=>
{
return
axios
.
get
(
"https://api.openweathermap.org/data/2.5/weather?q="
+
encodedStation
+
"&appid="
+
weatherAPIKey
)
.
then
(
function
(
response
)
{
// console.log("RES :: ", response["data"]["weather"]);
return
response
[
"data"
][
"weather"
][
0
];
})
.
catch
(
function
(
error
)
{
console
.
log
(
error
.
response
);
});
};
const
getPosition
=
(
lat
,
lon
)
=>
{
return
axios
.
get
(
...
...
@@ -58,6 +93,29 @@ const getPosition = (lat, lon) => {
console
.
log
(
error
.
response
);
});
};
const
getEnglishPosition
=
(
lat
,
lon
)
=>
{
return
axios
.
get
(
"https://maps.googleapis.com/maps/api/geocode/json?latlng="
+
lat
+
","
+
lon
+
"&location_type=ROOFTOP&result_type=street_address&key="
+
googleMapKey
+
"&language=en"
)
.
then
(
function
(
response
)
{
let
stationName
=
response
[
"data"
].
results
[
0
][
"address_components"
][
3
][
"long_name"
];
console
.
log
(
"STATION : "
,
stationName
);
return
(
encodedStation
=
encodeURI
(
stationName
));
})
.
catch
(
function
(
error
)
{
console
.
log
(
error
.
response
);
});
};
/* GET route airCondition listing. */
router
.
get
(
"/route"
,
async
function
(
req
,
res
,
next
)
{
console
.
log
(
"출발지:"
,
req
.
query
.
departure
);
...
...
Please
register
or
login
to post a comment