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

万网有网站建设吗做网站什么职业

万网有网站建设吗,做网站什么职业,wordpress数据库添加用户,网站的劣势使用Android Studio开发天气预报APP 今天我来分享一下如何使用Android Studio开发一个天气预报APP。在文中#xff0c;我们将使用第三方接口获取实时天气数据#xff0c;并显示在APP界面上。 步骤一#xff1a;创建新项目 首先#xff0c;打开Android Studio并创建一个新…使用Android Studio开发天气预报APP 今天我来分享一下如何使用Android Studio开发一个天气预报APP。在文中我们将使用第三方接口获取实时天气数据并显示在APP界面上。 步骤一创建新项目 首先打开Android Studio并创建一个新的项目。在创建新项目时我们需要设置项目名称、包名和支持的最低API级别。 步骤二 为了获取实时天气数据我们需要导入一个名为Retrofit的第三方库。可以使用以下代码在build.gradle文件中添加Retrofit库的依赖。 dependencies {implementation androidx.core:core-ktx:1.7.0implementation androidx.appcompat:appcompat:1.6.1implementation com.google.android.material:material:1.9.0implementation androidx.constraintlayout:constraintlayout:2.1.4testImplementation junit:junit:4.13.2androidTestImplementation androidx.test.ext:junit:1.1.5androidTestImplementation androidx.test.espresso:espresso-core:3.5.1 //networkimplementation com.squareup.retrofit2:retrofit:2.9.0implementation com.squareup.retrofit2:converter-gson:2.9.0 }步骤三获取API Key 为了使用OpenWeatherMap API您需要注册一个免费的API Key。请访问OpenWeatherMap官网进行注册并获取API Key。 步骤四创建接口 首先我们需要创建一个接口定义我们需要的网络请求方法。在这个例子中我们需要一个根据城市名称获取天气信息的方法 interface WeatherService {GET(weather)fun getWeatherByCityName(Query(q) cityName : String,Query(appid) apiKey : String) : CallWeatherResponse}步骤五构建对应的数据结构 这是对应的WeatherRespone数据结构用来序列化返回的json接口。 这个json结构可以从openweathermap的api里查看到 返回值在这里 根据OpenWeatherMap API的响应格式我们需要创建相应的数据模型。这里我们以WeatherResponse为例创建对应的数据模型类对应的kotlin结构体 data class WeatherResponse(SerializedName(coord)var coord: Coord? null,SerializedName(weather)var weather : ArrayListWeather,SerializedName(base)var base: String? null,SerializedName(main)var main: Main? null,SerializedName(visibility)var visibility: Int 0,SerializedName(wind)var wind: Wind ? null,SerializedName(clouds)var clouds: Clouds ? null,SerializedName(dt)val dt: Int,SerializedName(sys)var sys: Sys ? null,SerializedName(id)var id: Int 0,SerializedName(name)var name: String ? null,SerializedName(cod)var cod: Int )class Coord {SerializedName(lon)var lon : Float 0.toFloat()SerializedName(lat)var lat : Float 0.toFloat() }class Weather {SerializedName(id)var id: Int 0SerializedName(main)var main: String ? nullSerializedName(description)var description: String ? nullSerializedName(icon)var icon: String ? null }class Main {SerializedName(temp)var temp: Float 0.toFloat()SerializedName(pressure)var pressure: Int 0SerializedName(humidity)var humidity: Int 0SerializedName(temp_min)var temp_min: Float 0.toFloat()SerializedName(temp_max)var temp_max: Float 0.toFloat() }class Wind {SerializedName(speed)var speed: Float 0.toFloat()SerializedName(deg)var deg: Int 0 }class Clouds {SerializedName(clouds)var clouds: Int 0 }class Sys {SerializedName(type)var type: Int 0SerializedName(id)var id: Int 0SerializedName(message)var message: Float 0.toFloat()SerializedName(country)var country: String ? nullSerializedName(sunrise)var sunrise: Int 0SerializedName(sunset)var sunset: Int 0 }步骤六创建Retrofit实例 接下来我们需要创建一个Retrofit实例并配置相关参数。在这个例子中我们需要配置基础URL和Gson转换器 调用getWeatherByCityName(“London”)来获取伦敦的天气情况 object RetrofitClient {private const val BASE_URL https://api.openweathermap.org/data/2.5/private const val API_KEY add your api keyprivate val retrofit Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();private val weatherService: WeatherService by lazy { retrofit.create(WeatherService::class.java) }fun getWeatherByCityName(cityName: String) {val call weatherService.getWeatherByCityName(cityName, API_KEY)call.enqueue(object : CallbackWeatherResponse {override fun onResponse(call: CallWeatherResponse,response: ResponseWeatherResponse) {if (response.isSuccessful) {val weatherData response.body()handleWeatherData(weatherData)} else {handleWeatherFailure(response.message())}}override fun onFailure(call: CallWeatherResponse, t: Throwable) {handleWeatherFailure(t.message!!)}})}private fun handleWeatherData(weatherData: WeatherResponse?) {if (weatherData ! null) {println(coord: lat:${weatherData.coord?.lat},lon:${weatherData.coord?.lon})for(weather in weatherData.weather) {println(weather: id:${weather.id},main${weather.main}, description:${weather.description},icon:${weather.icon})}println(base:${weatherData.base})println(main: temperature:${weatherData.main?.temp},pressure:${weatherData.main?.pressure}, humidity:${weatherData.main?.humidity},temperature_min:${weatherData.main?.temp_min}, temperature_max:${weatherData.main?.temp_max})println(visibility:${weatherData.visibility})println(wind: speed:${weatherData.wind?.speed},deq:${weatherData.wind?.deg})println(clouds: clouds:${weatherData.clouds?.clouds})println(dt: ${weatherData.dt})println(sys: type:${weatherData.sys?.type},id:${weatherData.sys?.id},message:${weatherData.sys?.message} ,country:${weatherData.sys?.country},sunrise:${weatherData.sys?.sunrise},sunset:${weatherData.sys?.sunset})println(id: ${weatherData.id})println(name: ${weatherData.name})println(cod: ${weatherData.cod})}}private fun handleWeatherFailure(message: String) {println(Request failed: $message)} }步骤七程序的运行结果 W/ample.myweathe: Accessing hidden method Landroid/os/Trace;-asyncTraceBegin(JLjava/lang/String;I)V (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/os/Trace;-asyncTraceEnd(JLjava/lang/String;I)V (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/os/Trace;-traceCounter(JLjava/lang/String;I)V (light greylist, reflection) I/System.out: coord: lat:51.5085,lon:-0.1257 I/System.out: weather: id:804,mainClouds,description:overcast clouds,icon:04n I/System.out: base:stations I/System.out: main: temperature:285.53,pressure:1007,humidity:91,temperature_min:284.02,temperature_max:286.53 I/System.out: visibility:10000 I/System.out: wind: speed:0.82,deq:347 I/System.out: clouds: clouds:0 I/System.out: dt: 1690252945 I/System.out: sys: type:2,id:2075535,message:0.0,country:GB,sunrise:1690258398,sunset:1690315226 I/System.out: id: 2643743 I/System.out: name: London I/System.out: cod: 200 W/ample.myweathe: Accessing hidden method Landroid/graphics/FontFamily;-init()V (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/graphics/FontFamily;-addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/graphics/FontFamily;-addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/graphics/FontFamily;-freeze()Z (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/graphics/FontFamily;-abortCreation()V (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/graphics/Typeface;-createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (light greylist, reflection)
http://www.yutouwan.com/news/54039/

相关文章:

  • 如何利用某个软件做一个网站wordpress user login
  • 长沙企业网站建设公pc网站自动生成app
  • 网站页面可以用什么框架做微信小程序api文档
  • 网站客户端制作多少钱技术支持 嘉兴网站建设
  • 中英文双语网站宁波建设网查询
  • 抚州市城乡建设局网站四川建设厅的网站
  • 中国建设银行网站会员注册动漫设计一年学费多少
  • 哪里有做网站服务商北京城乡建设学校网站
  • 美工做网站尺寸多少授权登录网站怎么做
  • access做网站数据方法wordpress 获得文章的类别
  • 网站后期维护工作包括哪些西部网站管理助手 伪静态
  • 阳泉网站建设费用wordpress增加内存
  • 简单的网站建设秦皇岛微信公众号
  • 网站策划书的撰写wordpress 屏蔽国外ip
  • 网站怎么设置qq怎样购买域名
  • 广东商城网站建设报价常州男科医院哪一个好
  • 网站的软文 怎么做推广英文网站怎么推广
  • 宣讲家网站做四讲四有模范wordpress主题grace7
  • 静态网站登陆怎么做深圳app网站建设陈俊兵
  • 个人域名备案做企业网站英文企业网站模板
  • 如何在百度创建网站网站上传服务器教程
  • 网站策划的重要性自己做彩票网站犯法吗
  • 网站备案用英文中国手工活加工网官网
  • 网站开发创新点网站被入侵别人是怎么做跳转的
  • 社交网站建设网站软件工程师报名
  • 强生网站还要怎样做做网站的公司算外包公司吗
  • 太原住房与城乡建设厅网站前端会员中心wordpress
  • 南昌百度网站快速排名邢台学校网站建设报价
  • 一诺互联网站建设公司家电网站首页制作
  • 昆山网站维护南通做网站的公司