• 根据百度,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);
  • 相关阅读:
    hadoop之 distcp(分布式拷贝)
    LINUX下mysql客户端不能输入中文
    logstash-input-jdbc配置说明
    数据收集之binlog同步 Maxwell --->Kafka
    MySQL的binlog日志
    SqlServer字段说明查询及快速查看表结构
    【HTTP】C1-Web及网络基础
    第 2 期:['1', '2', '3'].map(parseInt) what & why
    用表单处理用户输入
    德国Vue.js2终极开发教程033--
  • 原文地址:https://www.cnblogs.com/dzhengyang/p/7099909.html
Copyright © 2020-2023  润新知