当前位置: 首页 > 知识库问答 >
问题:

如何从OpenWeatherMap获取图标

鲁熙云
2023-03-14

我想得到openweathermap图标。https://openweathermap.org/weather-conditions和http://samples.openweathermap.org/data/2.5/weather?q=London,英国

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int position, long id) {
            String text = (String) listView.getItemAtPosition(position);



            Factory.getInstance().havaModel(text,APPID_KEY).enqueue(new Callback<HavaModel>() {
                @Override
                public void onResponse(Call<HavaModel> call, Response<HavaModel> response) {
                    textView.setText(Float.toString((float) (response.body().main.temp-273.15)));
                    textView2.setText(Float.toString(response.body().coord.lon));
                    textView3.setText(Integer.toString(response.body().main.humidity));
                    textView4.setText(response.body().name);
                    imageView.getResources()



                }

非常感谢你。你的建议对我很重要

共有2个答案

夏侯朝斑
2023-03-14
{
    "coord": {
        "lon": -0.13,
        "lat": 51.51
    },
    "weather": [
        {
            "id": 500,
            "main": "Rain",
            "description": "light rain",
            "icon": "10n"
        }
    ],

从上面的json可以获得图标Id,并使用以下url加载图像http://openweathermap.org/img/w/10n.png

这里有相关官方文件的链接

朱慈
2023-03-14

图标的文档在这里。

http://openweathermap.org/weather-conditions

您将从JSON调用返回的对象中获取图标代码,如您的问题所示,然后使用该代码构建一个指向图标的url,

String iconUrl = "http://openweathermap.org/img/w/" + iconCode + ".png";

您还可以使用图像加载库将图像加载到您的ImageView中-例如:-使用毕加索图像库-

将此添加到您的构建中。格雷德尔锉刀-

compile 'com.squareup.picasso:picasso:2.5.2'

然后使用下面的代码将图像加载到ImageView中-

Picasso.with(context).load(iconUrl).into(imageView);

希望这有帮助!

 类似资料:
  • 问题内容: 我使用以下代码将单元格渲染更改为显示图像而不是文本: 现在,我希望能够获取中的每一行的图像,以便将其保存在数据库中。我该怎么办? 问题答案: 我无法抗拒这样的例子

  • 问题内容: 如何从Uri获取Bitmap对象(如果我成功将其存储在 以在应用程序中使用它? 有谁知道如何实现这一目标? 问题答案: 这是正确的方法: 如果您需要加载非常大的图像,则以下代码会将其加载到图块中(避免大内存分配):

  • 所以…我得到了一个调用Api,其中还包括7天的预测。我设法显示了当前的天气(温度和图标),但如何获得未来4天的天气预报? 我的API:https://api.openweathermap.org/data/2.5/onecall?lat=lat 我的型号: 我的回答是: 响应对象: 来自OneCall API的JSON:

  • 我正在建立一个阳光应用从Udacity课程。在第2课中,我尝试将应用程序连接到OpenWeatherMap.org站点上的云,以获取城市的天气数据。首先,基本查询起作用,即URL URL=新URL(“http://api.openweathermap.org/data/2.5/forecast?id=524901&appid=c21566b1153f87e9f1d256b962cd6d42”);但

  • 我试图给我的界面一个新的功能,但我遇到了一些障碍。当鼠标移动时,我想放大JLabel上的图像。以下是我的JLabels的外观: 代码一直在继续。我想创建一个函数并将其添加到mouseListener中,这样所有的行为都将相同。我想实现这一点: 但是我不知道我可以使用这个,因为java说我需要图像来创建我的放大图像图标 如何从代码中检索用于打包JLabel的图像。任何帮助都将不胜感激。

  • 问题内容: 问题 从地图中获取数据 资料格式 注意 如何从上述结果中获得以下值 1.Event_dtmReleaseDate 2.strID 3.Trans_strGuestList 我试过的 res.Map(“ Event_dtmReleaseDate”); 错误:res.Map未定义(类型map [string] interface {}没有字段或方法Map) res.Event_dtmRel