根据百度,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);

 

转载于:https://www.cnblogs.com/dzhengyang/p/7099909.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值