zoukankan      html  css  js  c++  java
  • 根据百度,gps坐标获取天气

    楼主用的是阿里天气免费版,限制1000次,可以重复购买

    下面放代码

                var orgWindow = new OrganizeWindowProxy(WorkContext);
                var orgInfo = orgWindow.GetInfoByID(organizeId);
                var coord = orgInfo.Map.MapList[0];
                string lat = "0", lng = "0";
                if (coord != null)
                {
                    lat = coord.Lat; lng = coord.Lnd;
                }
                const String host = "http://saweather.market.alicloudapi.com";
                const String path = "/gps-to-weather";
                const String method = "GET";
                const String appcode = "1e37984a57494b14ae6131e760651397";
                String querys = string.Format("from=5&lat={0}&lng={1}&need3HourForcast=0&needAlarm=0&needHourData=0&needIndex=0&needMoreDay=0", lat, lng);
                String bodys = "";
                String url = host + path;
                HttpWebRequest httpRequest = null;
                HttpWebResponse httpResponse = null;
    
                if (0 < querys.Length)
                {
                    url = url + "?" + querys;
                }
                httpRequest = (HttpWebRequest)WebRequest.Create(url);
                httpRequest.Method = method;
                httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
                if (0 < bodys.Length)
                {
                    byte[] data = Encoding.UTF8.GetBytes(bodys);
                    using (Stream stream = httpRequest.GetRequestStream())
                    {
                        stream.Write(data, 0, data.Length);
                    }
                }
                try
                {
                    httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                }
                catch (WebException ex)
                {
                    httpResponse = (HttpWebResponse)ex.Response;
                }
                Stream st = httpResponse.GetResponseStream();
                StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
                var weatherJosn = reader.ReadToEnd();
                return Json(weatherJosn, JsonRequestBehavior.AllowGet);
  • 相关阅读:
    pandas基础--汇总和计算描述统计
    pandas基础--基本功能
    pandas rank()函数简介
    pandas基础--数据结构:索引对象
    pandas基础--数据结构:DataFrame
    pands基础--数据结构:Series
    numpy cumsum()函数简介
    numpy基础--random模块:随机数生成
    vueJS 一天上手到精通
    set .net principle
  • 原文地址:https://www.cnblogs.com/dzhengyang/p/7099909.html
Copyright © 2011-2022 走看看