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);
  • 相关阅读:
    ExtJS小试 TreePanel
    ExtJS 之panel tabpanel 和window 的简单使用
    ExtJs2.1未知明错误
    Extjs xtype
    ibatis 初体验
    MS数据库分页
    EXTJS 简单登陆
    php5.2.9 apache2.2 mysql5.1 phpMyAdmin3.2配置
    安装配置Ruby for Eclipse
    ExtJs之gridPanel初探
  • 原文地址:https://www.cnblogs.com/dzhengyang/p/7099909.html
Copyright © 2011-2022 走看看