コード例 #1
0
        /*
         * http://openapi.airkorea.or.kr/openapi/services/rest/MsrstnInfoInqireSvc/getTMStdrCrdnt?
         * umdName=일도이동
         * &pageNo=1
         * &numOfRows=10
         * &ServiceKey=73Jjl5lZRvBRKkGsPnGmZ7EL9JtwsWNi3hhCIN8cpVJzMdRRgyzntwz2lHmTKeR1tp7NWzoihNGGazcDEFgh8w%3D%3D
         * &_returnType=json
         *
         */
        private static async Task <AirDataResult> GetAirData(string url, string umd)
        {
            JusoResult jibunJuso = await GetJibunJuso(umd);

            string page = url +
                          "umdName=" + UtilManager.GetUmdFromAddress(jibunJuso.results.juso[0].jibunAddr) +
                          "&pageNo=1" +
                          "&numOfRows=10" +
                          "&ServiceKey=" + ServiceKeyForAir +
                          "&_returnType=json";

            Console.WriteLine("GetAirData says: {0}", page);

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                using (HttpResponseMessage response = await client.GetAsync(page))
                    using (HttpContent content = response.Content)
                    {
                        // TmX, TmY 조회
                        var stringResult = await content.ReadAsStringAsync();

                        AirDataMetaResult resultTmXY = JsonConvert.DeserializeObject <AirDataMetaResult>(stringResult);

                        // 측정소명 조회
                        AirDataMetaResult resultStationName = await GetStationName("http://openapi.airkorea.or.kr/openapi/services/rest/MsrstnInfoInqireSvc/getNearbyMsrstnList?",
                                                                                   resultTmXY.list[0].tmX, resultTmXY.list[0].tmY);

                        // 측정값 조회
                        AirDataResult result = await GetAirMeasure("http://openapi.airkorea.or.kr/openapi/services/rest/ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?",
                                                                   resultStationName.list[0].stationName);

                        return(result);
                    }
            }
        }
コード例 #2
0
        /*
         * http://openapi.airkorea.or.kr/openapi/services/rest/MsrstnInfoInqireSvc/getNearbyMsrstnList?
         * tmX=157273.257218
         * &tmY=1213.917415
         * &pageNo=1
         * &numOfRows=10
         * &ServiceKey=73Jjl5lZRvBRKkGsPnGmZ7EL9JtwsWNi3hhCIN8cpVJzMdRRgyzntwz2lHmTKeR1tp7NWzoihNGGazcDEFgh8w%3D%3D
         * &_returnType=json
         *
         */
        private static async Task <AirDataMetaResult> GetStationName(string url, string tmX, string tmY)
        {
            string page = url +
                          "tmX=" + tmX +
                          "&tmY=" + tmY +
                          "&pageNo=1" +
                          "&numOfRows=10" +
                          "&ServiceKey=" + ServiceKeyForAir +
                          "&_returnType=json";

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                using (HttpResponseMessage response = await client.GetAsync(page))
                    using (HttpContent content = response.Content)
                    {
                        var stringResult = await content.ReadAsStringAsync();

                        AirDataMetaResult result = JsonConvert.DeserializeObject <AirDataMetaResult>(stringResult);
                        return(result);
                    }
            }
        }