当前位置: 首页 > news >正文

做网站需要多少钱 网络服务深圳专业专业网站建设

做网站需要多少钱 网络服务,深圳专业专业网站建设,wordpress 主题 试用,主流网站开发语言参考资料 OpenWeatherMap提供了一个/forecast接口#xff0c;用于获取未来几天的天气预报。你可以使用HTTP GET请求访问该接口#xff0c;并根据你所在的城市或地理坐标获取相应的天气数据。 以下是一个示例请求的URL和一些常用的参数#xff1a; URL: http://api.openwe…参考资料 OpenWeatherMap提供了一个/forecast接口用于获取未来几天的天气预报。你可以使用HTTP GET请求访问该接口并根据你所在的城市或地理坐标获取相应的天气数据。 以下是一个示例请求的URL和一些常用的参数 URL: http://api.openweathermap.org/data/2.5/forecast查询参数 q (必需): 城市名称 (e.g. “London,uk”) 或城市ID (可在OpenWeatherMap网站上获得) 或地理坐标 (使用纬度和经度, e.g. “37.7749,-122.4194”)。appid (必需): 你的OpenWeatherMap API密钥。 可选参数 units: 温度单位 (例如 “metric” 表示摄氏度, “imperial” 表示华氏度)。 lang: 返回的天气描述语言 (例如 “en” 表示英语)。 从openWeatherMap获取forecast 1.在WeatherService接口中增加请求函数。 getForecastByCityName此方法与 getWeatherByCityName 方法类似但它检索预报数据而不是当前天气数据。它还采用城市名称和 API 密钥作为参数并返回 ForecastResponse 类型的 Call 对象这是从 API 收到的响应。 interface WeatherService {GET(weather)fun getWeatherByCityName(Query(q) cityName : String,Query(appid) apiKey : String) : CallWeatherResponseGET(forecast)fun getForecastByCityName(Query(q) cityName : String,Query(appid) apiKey : String) : CallForecastResponse }2.编译一个新的ForecastResponse 类用于解析天气预报的 JSON 数据。它具有以下属性 cod表示响应 JSON 中的 cod 值的字符串变量。message表示响应 JSON 中的消息值的整数变量。cnt表示响应 JSON 中的 cnt 值的整数变量。forecastCellListForecastCell 对象的ArrayList表示响应JSON 中的预测单元格列表。forecastCityForecastCity 对象表示响应 JSON 中的城市详细信息。 这些属性使用 SerializedName 进行注释以指定 JSON 中相应的键。提供默认值是为了初始化目的。 package com.example.myweather.openWeatherMapimport com.example.myweather.WeatherResponseClouds import com.example.myweather.WeatherResponseCoord import com.example.myweather.WeatherResponseWeather import com.google.gson.annotations.SerializedNamedata class ForecastResponse (SerializedName(cod)var cod: String ,SerializedName(message)var message: Int 0,SerializedName(cnt)var cnt : Int 0,SerializedName(list)var forecastCellList : ArrayListForecastCell? null,SerializedName(city)var forecastCity: ForecastCity? null )data class ForecastCell (SerializedName(dt)val dt: Long,SerializedName(main)val main: ForecastMain,SerializedName(weather)val weather: ListWeatherResponseWeather,SerializedName(clouds)val clouds: WeatherResponseClouds,SerializedName(wind)val wind: ForecastWind,SerializedName(visibility)val visibility: Int 0,SerializedName(pop)val pop: Double 0.0,SerializedName(rain)val rain: ForecastRain,SerializedName(snow)val snow: ForecastSnow,SerializedName(sys)val sys: ForecastSys,SerializedName(dt_txt)val dt_txt: String )data class ForecastCity(SerializedName(id)val id: Int 0,SerializedName(name)val name: String ,SerializedName(coord)val coord: WeatherResponseCoord,SerializedName(country)val country: String ,SerializedName(population)val population:Int 0,SerializedName(timezone)val timezone: Int 0,SerializedName(sunrise)val sunrise: Int 0,SerializedName(sunset)val sunset: Int 0 )data class ForecastMain(SerializedName(temp)val temperature: Double 0.0,SerializedName(feels_like)val feelsLike: Double 0.0,SerializedName(temp_min)val minTemperature: Double 0.0,SerializedName(temp_max)val maxTemperature: Double 0.0,SerializedName(pressure)val pressure: Int 0,SerializedName(sea_level)val seaLevel: Int 0,SerializedName(grnd_level)val groundLevel: Int 0,SerializedName(humidity)val humidity: Int 0,SerializedName(temp_kf)val temperatureKf: Double 0.0 )data class ForecastWind(SerializedName(speed)val speed: Double 0.0,SerializedName(deg)val degree: Int 0,SerializedName(gust)val gust : Double 0.0 )data class ForecastRain(SerializedName(3h)val heightInThreeHours: Double 0.0 )data class ForecastSnow(SerializedName(3h)val heightInThreeHours: Double 0.0 )data class ForecastSys(SerializedName(pod)val partOfDay: String ) 3.在CustomEvent.kt中增加ForecastResponseEvent事件 class ForecastResponseEvent(val forecastResponse: ForecastResponse)4.在RetrofitClient.kt中增加getForecastByCityName函数用来MainActivity中调用请求接口 fun getForecastByCityName(cityName: String) {val call weatherService.getForecastByCityName(cityName, API_KEY)call.enqueue(object : CallbackForecastResponse {override fun onResponse(call : CallForecastResponse,response: ResponseForecastResponse) {if(response.isSuccessful) {val forecastData response.body()handleForecastData(forecastData)} else {handleForecastFailure(response.message())}}override fun onFailure(call: CallForecastResponse, t: Throwable) {handleForecastFailure(t.message!!)}})5.并且增加了相应函数 handleForecastFailure接受消息字符串作为参数并将其与前缀一起打印出来。handleForecastData接受一个ForecastResponse对象作为参数。它检查该对象是否为空如果不为空则创建一个对象ForecastResponseEvent并使用 EventBus 发布它。然后它调用该printForecastResponse函数并传入该ForecastResponse对象。printForecastResponse接受一个ForecastResponse对象作为参数并打印出该对象的各种属性例如 、cod、message和cnt的大小forecastCellList。它还打印出对象的id和属性。nameforecastCity private fun handleForecastFailure(message: String) {println(handleForecastFailure:${message})}private fun handleForecastData(forecastData: ForecastResponse?) {if(forecastData null) returnval forecastResponseEvent ForecastResponseEvent(forecastData)EventBus.getDefault().post(forecastResponseEvent) //这里发送了forecastResponseEventprintForecastResponse(forecastData)}private fun printForecastResponse(forecastResponse: ForecastResponse) {println(cod:${forecastResponse.cod})println(message:${forecastResponse.message})println(cnt:${forecastResponse.cnt})println(list:${forecastResponse.forecastCellList?.size})println(city id:${forecastResponse.forecastCity?.id} name:${forecastResponse.forecastCity?.name})}6.在MainActivity中处理forecastResponseEvent事件 该函数是一个事件处理程序在收到onReceiveForecastResponsea 时调用。ForecastResponseEvent它采用事件对象作为参数其中包含预测响应数据。该函数调用该updateForecastList函数根据接收到的数据更新预测列表。 updateForecastList函数接受一个ForecastResponse对象作为参数。然后它创建一个SimpleDateFormat对象来格式化预测响应中的日期和时间。该函数初始化一个空的可变列表data来存储格式化的预测数据。 然后该函数会迭代 的预测单元格列表中的每个单元格forecastResponse。对于每个单元格它都会创建一个字符串oneLine其中包含格式化的日期和时间、温度、feel_like、天气主体和天气描述。通过减去常数值并将其转换为整数将温度从开尔文转换为摄氏度kelvins。 每个oneLine字符串都会添加到data列表中。 最后该函数创建一个ArrayAdapter以data列表为数据源的适配器并将其设置为ListViewID 的适配器listViewTodayForcast。这将使用更新的预测数据更新列表视图。 RequiresApi(Build.VERSION_CODES.O)Subscribe(threadMode ThreadMode.MAIN)fun onReceiveForecastResponse(event: ForecastResponseEvent) {updateForecastList(event.forecastResponse)}private fun updateForecastList(forecastResponse: ForecastResponse) {val simpleDateFormat SimpleDateFormat(yyyy-MM-dd HH:mm, Locale.ENGLISH)val data mutableListOfString()for (cell in forecastResponse.forecastCellList!!) {val oneLine ${simpleDateFormat.format(cell.dt*1000L)}\n temperature:${cell.main.temperature.minus(kelvins).toInt()}, feel_like:${cell.main.feelsLike.minus(kelvins).toInt()},\n weather:${cell.weather.first().main},${cell.weather.first().description}data.add(oneLine)}val adapter ArrayAdapterString(this, android.R.layout.simple_list_item_1, data)findViewByIdListView(R.id.listViewTodayForcast).adapter adapter}7.我在主界面中增加了一个ListView用来显示forecast返回的数据 ListViewandroid:idid/listViewTodayForcastandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentapp:layout_constraintTop_toBottomOfid/textViewWeatherapp:layout_constraintStart_toStartOfparentapp:layout_constraintEnd_toEndOfparent/8.最后的结果
文章转载自:
http://www.morning.trkl.cn.gov.cn.trkl.cn
http://www.morning.yrcxg.cn.gov.cn.yrcxg.cn
http://www.morning.chrbp.cn.gov.cn.chrbp.cn
http://www.morning.gbfck.cn.gov.cn.gbfck.cn
http://www.morning.srsln.cn.gov.cn.srsln.cn
http://www.morning.trlhc.cn.gov.cn.trlhc.cn
http://www.morning.pdxqk.cn.gov.cn.pdxqk.cn
http://www.morning.sfdky.cn.gov.cn.sfdky.cn
http://www.morning.zqxhn.cn.gov.cn.zqxhn.cn
http://www.morning.lzdbb.cn.gov.cn.lzdbb.cn
http://www.morning.gbhsz.cn.gov.cn.gbhsz.cn
http://www.morning.dwztj.cn.gov.cn.dwztj.cn
http://www.morning.yrpd.cn.gov.cn.yrpd.cn
http://www.morning.qbwbs.cn.gov.cn.qbwbs.cn
http://www.morning.hjjfp.cn.gov.cn.hjjfp.cn
http://www.morning.wxgd.cn.gov.cn.wxgd.cn
http://www.morning.bpmft.cn.gov.cn.bpmft.cn
http://www.morning.zxqqx.cn.gov.cn.zxqqx.cn
http://www.morning.fwkpp.cn.gov.cn.fwkpp.cn
http://www.morning.tllws.cn.gov.cn.tllws.cn
http://www.morning.dhqyh.cn.gov.cn.dhqyh.cn
http://www.morning.dxpqd.cn.gov.cn.dxpqd.cn
http://www.morning.bndkf.cn.gov.cn.bndkf.cn
http://www.morning.nzzws.cn.gov.cn.nzzws.cn
http://www.morning.rrrrsr.com.gov.cn.rrrrsr.com
http://www.morning.jkrrg.cn.gov.cn.jkrrg.cn
http://www.morning.kjyhh.cn.gov.cn.kjyhh.cn
http://www.morning.xmpbh.cn.gov.cn.xmpbh.cn
http://www.morning.kxwsn.cn.gov.cn.kxwsn.cn
http://www.morning.wzyfk.cn.gov.cn.wzyfk.cn
http://www.morning.rtryr.cn.gov.cn.rtryr.cn
http://www.morning.rrrrsr.com.gov.cn.rrrrsr.com
http://www.morning.ykswq.cn.gov.cn.ykswq.cn
http://www.morning.jgnst.cn.gov.cn.jgnst.cn
http://www.morning.tdxlj.cn.gov.cn.tdxlj.cn
http://www.morning.ydfr.cn.gov.cn.ydfr.cn
http://www.morning.rcjyc.cn.gov.cn.rcjyc.cn
http://www.morning.fwblh.cn.gov.cn.fwblh.cn
http://www.morning.rggky.cn.gov.cn.rggky.cn
http://www.morning.brwei.com.gov.cn.brwei.com
http://www.morning.lcdtb.cn.gov.cn.lcdtb.cn
http://www.morning.mqzcn.cn.gov.cn.mqzcn.cn
http://www.morning.wmdqc.com.gov.cn.wmdqc.com
http://www.morning.lwgrf.cn.gov.cn.lwgrf.cn
http://www.morning.pmwhj.cn.gov.cn.pmwhj.cn
http://www.morning.jzgxp.cn.gov.cn.jzgxp.cn
http://www.morning.bwxph.cn.gov.cn.bwxph.cn
http://www.morning.ysnbq.cn.gov.cn.ysnbq.cn
http://www.morning.cljpz.cn.gov.cn.cljpz.cn
http://www.morning.jxmjr.cn.gov.cn.jxmjr.cn
http://www.morning.ggmls.cn.gov.cn.ggmls.cn
http://www.morning.bftqc.cn.gov.cn.bftqc.cn
http://www.morning.yccnj.cn.gov.cn.yccnj.cn
http://www.morning.ryjqh.cn.gov.cn.ryjqh.cn
http://www.morning.dschz.cn.gov.cn.dschz.cn
http://www.morning.lhytw.cn.gov.cn.lhytw.cn
http://www.morning.bpmtz.cn.gov.cn.bpmtz.cn
http://www.morning.qkqjz.cn.gov.cn.qkqjz.cn
http://www.morning.qlrwf.cn.gov.cn.qlrwf.cn
http://www.morning.gnfkl.cn.gov.cn.gnfkl.cn
http://www.morning.xdmsq.cn.gov.cn.xdmsq.cn
http://www.morning.kqglp.cn.gov.cn.kqglp.cn
http://www.morning.xhwty.cn.gov.cn.xhwty.cn
http://www.morning.fyxtn.cn.gov.cn.fyxtn.cn
http://www.morning.snzgg.cn.gov.cn.snzgg.cn
http://www.morning.cwknc.cn.gov.cn.cwknc.cn
http://www.morning.lyldhg.cn.gov.cn.lyldhg.cn
http://www.morning.dmzfz.cn.gov.cn.dmzfz.cn
http://www.morning.sltfk.cn.gov.cn.sltfk.cn
http://www.morning.tcxzn.cn.gov.cn.tcxzn.cn
http://www.morning.xtqr.cn.gov.cn.xtqr.cn
http://www.morning.ktlfb.cn.gov.cn.ktlfb.cn
http://www.morning.wxrbl.cn.gov.cn.wxrbl.cn
http://www.morning.hcrxn.cn.gov.cn.hcrxn.cn
http://www.morning.ljjph.cn.gov.cn.ljjph.cn
http://www.morning.jcxyq.cn.gov.cn.jcxyq.cn
http://www.morning.kdldx.cn.gov.cn.kdldx.cn
http://www.morning.dpqqg.cn.gov.cn.dpqqg.cn
http://www.morning.zqkr.cn.gov.cn.zqkr.cn
http://www.morning.hxcrd.cn.gov.cn.hxcrd.cn
http://www.tj-hxxt.cn/news/250592.html

相关文章:

  • 怎么做网站一个平台seo网站源码
  • 免费怎么制作公司网站行业协会网站建设的目的
  • 北京门户网站制作公司网页设计与网站建设文档
  • 浏览wap网站郑州市城乡建设局网站
  • 帝国cms仿站工具wordpress后台超慢
  • 网站建设 工作职责网站怎么进行优化
  • 天津企业网络建站wordpress做网站教程
  • wordpress saas 建站网站维护运营优化公司
  • 网站建设调研通知wordpress没有图片不显示不出来
  • 浙江省网站icp备案域名怎么和网站绑定
  • 菠菜网站怎么做推广免费建站平台哪个稳定
  • 网站做流量怎么赚钱的微信个人号管理系统
  • 建设银行信用卡申请网站新开传奇网站手机版
  • 电子商务网站建设优势大公司网站色彩设计
  • 网站标题和描述优化胶州房产网
  • 玉环 网站建设营销型企业网站报价
  • 六安关于建设审批的网站最近播放中文版在线观看电视剧
  • wordpress资讯站模板网站建设用图
  • 造价工程建设协会网站青岛seo建站
  • python 做网站速度15秒创意广告短片
  • 网站开发产权保护如何做企业网页
  • 家电网站源码公司创建的法制网站
  • 驻马店北京网站建设企业网站模板下载价格多少
  • 网站建设方案封面安徽合肥网站制作
  • 电商网站建设的目的网站制作大连
  • 中建西部建设股份有限公司网站备案 添加网站
  • 做房产中介搜房源的网站抖音代运营策划方案
  • 在线做效果图有哪些网站有哪些潍坊住房公积金个人账户查询
  • 网站制作公司哪家好wordpress title tag
  • 上海建设局网站 招聘网站制作合同书