공공데이터포털 에서 아래와 같은 API 서비스를 이용하였다.


1. 측정소정보 조회 서비스



측정소 정보 서비스 조회하기 이다.  실제 대기오염 지표를 조회하는 방법중 현재 위치에 근처에 있는 근접 측정소를 조회한뒤 해당 측정소에 대기오염 지표를 조회한다. 




2. 대기오염정보 조회 서비스



대기오염 정보조회 서비스를 이용해서 대기오염지수를 조회한다. 먼저 조회해서 확인해볼 데이터는 측정소별 실시간 측정정보 조회이다.  해당 API에 대한 자세한 정보는 airkorea_openapi_guide-v1_6_1.docx 통해서  확인가능하다.



3. 근접측정소 목록 조회 하기






TM 좌표를 기준으로 가장 가까운 측정소 list를 구한다. 

TM좌표 구하는 방법에 대한것은 이전 포스팅을 참고한다.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
async function getNearbyMsrstnList(tmX, tmY) {
    let url = `${API_NMT}?tmX=${tmX}&tmY=${tmY}&pageNo=1&numOfRows=10&ServiceKey=${SERVICE_KEY}&_returnType=json`;
    
    let res = await fetch(url)
    .then(response => response.json())
    .then(data => {
        
        // data.list.
       let tms = _.minBy(data.list, 'tm');
       
       return tms;
       
    })
    .catch(error => {
        console.log("error");
        
    });
    return await getMsrstnAcctoRltmMesureDnsty(res.stationName);
}

cs


tm좌표를 기준으로 가장 가까운 측정소 리스트를 조회한다음, 현재 위치에서 측정소 거리가 가장 가까운 Object를 찾는다. 



4. 측정소별 실시간 정보 조회 하기





측정소별 실시간 측정정보를 조회하기 위해서는 측정소명이 필요한데  근접측정소 목록 조회결과 값으로 측정소 명을 알 수 있다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
async function getMsrstnAcctoRltmMesureDnsty(stationName) {
    let url = `${API_MSRSTN}?stationName=${encodeURIComponent(stationName)}&dataTerm=${DATA_TYPE}&pageNo=1&numOfRows=1&ServiceKey=${SERVICE_KEY}&_returnType=json`;
    console.log(url);
    return await fetch(url)
    .then(response => response.json())
    .then(data => {
        console.log("getMsrstnAcctoRltmMesureDnsty");
        console.log(data.list);
        console.log(data.list[0].mangName);
        console.log(data.list[0].dataTime);
        console.log(data.list[0].pm10Grade);
        console.log(data.list[0].pm10Value);
        console.log(data.list[0].pm25Grade);
        console.log(data.list[0].pm25Value);
        console.log(data.list[0].so2Value);
        console.log(data.list[0].so2Grade);
 
        console.log(data.list[0].coGrade);
        console.log(data.list[0].coValue);
        console.log(data.list[0].khaiGrade);
        console.log(data.list[0].khaiValue);
       
        return data.list[0];
    })
    .catch(error => {
        console.log("error");
        console.log(error);
        
    });
}

cs






블로그 이미지

클라인STR

,