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);
  • 相关阅读:
    SpringMVC 高级开发(异常页面处理,json传输数据,文件上传)
    SpringMVC中的Controller方法的(返回值/参数类型)
    SpringMVC的其他注解
    SpringMVC的整合,基于注解
    SpringMVC入门程序:helloWorld
    SpringMVC入门
    SpringAOP事务的实现
    仅需三步,即可在Vue项目中配置sass
    前端常用的设计模式
    call和apply的区别及其用法
  • 原文地址:https://www.cnblogs.com/dzhengyang/p/7099909.html
Copyright © 2011-2022 走看看