Merge branch 'feature/add_Weather_API' into feature/Location
# Conflicts: # node_modules/.package-lock.json # package-lock.json # package.json # readme.md
Showing
10 changed files
with
177 additions
and
0 deletions
.vscode/launch.json
0 → 100644
1 | +{ | ||
2 | + // Use IntelliSense to learn about possible attributes. | ||
3 | + // Hover to view descriptions of existing attributes. | ||
4 | + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
5 | + "version": "0.2.0", | ||
6 | + "configurations": [ | ||
7 | + { | ||
8 | + "type": "pwa-node", | ||
9 | + "request": "launch", | ||
10 | + "name": "Launch Program", | ||
11 | + "skipFiles": [ | ||
12 | + "<node_internals>/**" | ||
13 | + ], | ||
14 | + "program": "${workspaceFolder}/Weather.js" | ||
15 | + } | ||
16 | + ] | ||
17 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
Weather.js
0 → 100644
1 | +const request = require('request'); | ||
2 | +const moment = require('moment'); | ||
3 | +require('moment-timezone'); | ||
4 | +moment.tz.setDefault("Asia/seoul"); | ||
5 | +let today = new String(get_base_date()); | ||
6 | +let time = new String(get_base_time()); | ||
7 | +var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'; | ||
8 | +var queryParams = '?' + encodeURIComponent('serviceKey') + '=API KEY'; /* Service Key*/ | ||
9 | +queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ | ||
10 | +queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('10'); /* */ | ||
11 | +queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ | ||
12 | +queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(today); /* */ | ||
13 | +queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2000'); /* */ | ||
14 | +queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent('55'); /* */ | ||
15 | +queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent('127'); /* */ | ||
16 | + | ||
17 | + | ||
18 | +function get_base_date() // 날짜 추출 함수 | ||
19 | +{ | ||
20 | + // 0000~0210 사이 시간대에 조회시 전일(date -1)로 변경 | ||
21 | + let date =moment().format('YYYYMMDD'); | ||
22 | + let time = new String(moment().format('HHmm')); | ||
23 | + if ('0000'<=time && time<'0210'){date -= 1} | ||
24 | + return date | ||
25 | +} | ||
26 | + | ||
27 | +function get_base_time() // 시간 추출 함수 | ||
28 | +{ | ||
29 | + //단기예보 | ||
30 | + //- Base_time : 0200, 0500, 0800, 1100, 1400, 1700, 2000, 2300 (1일 8회) | ||
31 | + //- API 제공 시간(~이후) : 02:10, 05:10, 08:10, 11:10, 14:10, 17:10, 20:10, 23:10 | ||
32 | + //- 시간대 맞추기 | ||
33 | + let time = new String(moment().format('HHmm')); | ||
34 | + if ('0000'<=time && time<'0210'){time = '2300'} | ||
35 | + else if ('0210'<=time && time<'0510'){time = '0200'} | ||
36 | + else if ('0510'<=time && time<'0810'){time = '0500'} | ||
37 | + else if ('0810'<=time && time<'1110'){time = '0800'} | ||
38 | + else if ('1110'<=time && time<'1410'){time = '1100'} | ||
39 | + else if ('1410'<=time && time<'1710'){time = '1400'} | ||
40 | + else if ('1710'<=time && time<'2010'){time = '1700'} | ||
41 | + else if ('2010'<=time && time<'2310'){time = '2010'} | ||
42 | + else if ('2310'<=time && time<'2359'){time = '2300'} | ||
43 | + return time | ||
44 | + } | ||
45 | + | ||
46 | +request({ | ||
47 | + url: url + queryParams, | ||
48 | + method: 'GET' | ||
49 | +}, function (error, response, body) { | ||
50 | + //console.log('Status', response.statusCode); | ||
51 | + //console.log('Headers', JSON.stringify(response.headers)); | ||
52 | + console.log('Reponse received', body); | ||
53 | +}); | ||
54 | + | ||
55 | + | ||
56 | + | ||
57 | + | ||
58 | +// 소스출처 : http://www.kma.go.kr/weather/forecast/digital_forecast.jsp 내부에 있음 | ||
59 | +// 기상청에서 이걸 왜 공식적으로 공개하지 않을까? | ||
60 | +// | ||
61 | +// (사용 예) | ||
62 | +// var rs = dfs_xy_conv("toLL","60","127"); | ||
63 | +// console.log(rs.lat, rs.lng); | ||
64 | +// | ||
65 | + | ||
66 | + //<!-- | ||
67 | + // | ||
68 | + // LCC DFS 좌표변환을 위한 기초 자료 | ||
69 | + // | ||
70 | + var RE = 6371.00877; // 지구 반경(km) | ||
71 | + var GRID = 5.0; // 격자 간격(km) | ||
72 | + var SLAT1 = 30.0; // 투영 위도1(degree) | ||
73 | + var SLAT2 = 60.0; // 투영 위도2(degree) | ||
74 | + var OLON = 126.0; // 기준점 경도(degree) | ||
75 | + var OLAT = 38.0; // 기준점 위도(degree) | ||
76 | + var XO = 43; // 기준점 X좌표(GRID) | ||
77 | + var YO = 136; // 기1준점 Y좌표(GRID) | ||
78 | + // | ||
79 | + // LCC DFS 좌표변환 ( code : "toXY"(위경도->좌표, v1:위도, v2:경도), "toLL"(좌표->위경도,v1:x, v2:y) ) | ||
80 | + // | ||
81 | + | ||
82 | + | ||
83 | + function dfs_xy_conv(code, v1, v2) { | ||
84 | + var DEGRAD = Math.PI / 180.0; | ||
85 | + var RADDEG = 180.0 / Math.PI; | ||
86 | + | ||
87 | + var re = RE / GRID; | ||
88 | + var slat1 = SLAT1 * DEGRAD; | ||
89 | + var slat2 = SLAT2 * DEGRAD; | ||
90 | + var olon = OLON * DEGRAD; | ||
91 | + var olat = OLAT * DEGRAD; | ||
92 | + | ||
93 | + var sn = Math.tan(Math.PI * 0.25 + slat2 * 0.5) / Math.tan(Math.PI * 0.25 + slat1 * 0.5); | ||
94 | + sn = Math.log(Math.cos(slat1) / Math.cos(slat2)) / Math.log(sn); | ||
95 | + var sf = Math.tan(Math.PI * 0.25 + slat1 * 0.5); | ||
96 | + sf = Math.pow(sf, sn) * Math.cos(slat1) / sn; | ||
97 | + var ro = Math.tan(Math.PI * 0.25 + olat * 0.5); | ||
98 | + ro = re * sf / Math.pow(ro, sn); | ||
99 | + var rs = {}; | ||
100 | + if (code == "toXY") { | ||
101 | + rs['lat'] = v1; | ||
102 | + rs['lng'] = v2; | ||
103 | + var ra = Math.tan(Math.PI * 0.25 + (v1) * DEGRAD * 0.5); | ||
104 | + ra = re * sf / Math.pow(ra, sn); | ||
105 | + var theta = v2 * DEGRAD - olon; | ||
106 | + if (theta > Math.PI) theta -= 2.0 * Math.PI; | ||
107 | + if (theta < -Math.PI) theta += 2.0 * Math.PI; | ||
108 | + theta *= sn; | ||
109 | + rs['x'] = Math.floor(ra * Math.sin(theta) + XO + 0.5); | ||
110 | + rs['y'] = Math.floor(ro - ra * Math.cos(theta) + YO + 0.5); | ||
111 | + } | ||
112 | + else { | ||
113 | + rs['x'] = v1; | ||
114 | + rs['y'] = v2; | ||
115 | + var xn = v1 - XO; | ||
116 | + var yn = ro - v2 + YO; | ||
117 | + ra = Math.sqrt(xn * xn + yn * yn); | ||
118 | + if (sn < 0.0) - ra; | ||
119 | + var alat = Math.pow((re * sf / ra), (1.0 / sn)); | ||
120 | + alat = 2.0 * Math.atan(alat) - Math.PI * 0.5; | ||
121 | + | ||
122 | + if (Math.abs(xn) <= 0.0) { | ||
123 | + theta = 0.0; | ||
124 | + } | ||
125 | + else { | ||
126 | + if (Math.abs(yn) <= 0.0) { | ||
127 | + theta = Math.PI * 0.5; | ||
128 | + if (xn < 0.0) - theta; | ||
129 | + } | ||
130 | + else theta = Math.atan2(xn, yn); | ||
131 | + } | ||
132 | + var alon = theta / sn + olon; | ||
133 | + rs['lat'] = alat * RADDEG; | ||
134 | + rs['lng'] = alon * RADDEG; | ||
135 | + } | ||
136 | + return rs; | ||
137 | + } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
node_modules/http/README.md
0 → 100644
1 | +# Security holding package | ||
2 | + | ||
3 | +This package name is not currently in use, but was formerly occupied | ||
4 | +by another package. To avoid malicious use, npm is hanging on to the | ||
5 | +package name, but loosely, and we'll probably give it to you if you | ||
6 | +want it. | ||
7 | + | ||
8 | +You may adopt this package by contacting support@npmjs.com and | ||
9 | +requesting the name. |
node_modules/http/package.json
0 → 100644
This diff is collapsed. Click to expand it.
1 | +<<<<<<< HEAD | ||
1 | 경위도 : https://developers.google.com/maps/documentation/javascript/examples/map-geolocation?hl=ko#maps_map_geolocation-javascript | 2 | 경위도 : https://developers.google.com/maps/documentation/javascript/examples/map-geolocation?hl=ko#maps_map_geolocation-javascript |
3 | +======= | ||
4 | +https://www.data.go.kr/tcs/dss/selectApiDataDetailView.do?publicDataPk=15084084 기상청 | ||
5 | +>>>>>>> feature/add_Weather_API | ... | ... |
No preview for this file type
No preview for this file type
No preview for this file type
-
Please register or login to post a comment