android - 开放天气图 API

标签 android android-menu openweathermap

如何使用 openweathermap API 从 android 菜单在 °C/°F 之间切换

enter image description here

菜单.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/degrees"
        android:title="Celsius / Fahrenheit"
        app:showAsAction="never"/>
</menu>

主要 Activity .java

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.menu.menu:
            // How do change between Celsius and Fahrenheit
                break;


        }
        return true;
    }
}

Dropbox 链接以获得更深入的 View (如果需要)

Weather Test app

最佳答案

来自OpenWeather Documentation.

单位格式

描述:

可以使用标准、公制和英制单位。

参数:

单位 公制、英制。当您不使用单位参数时,格式默认为标准。

Temperature is available in Fahrenheit, Celsius and Kelvin units.

For temperature in Fahrenheit use units=imperial
For temperature in Celsius use units=metric
Temperature in Kelvin is used by default, no need to use units parameter in API call

List of all API parameters with units openweathermap.org/weather-data

API 调用示例:

standard api.openweathermap.org/data/2.5/find?q=London
metric api.openweathermap.org/data/2.5/find?q=London&units=metric
imperial api.openweathermap.org/data/2.5/find?q=London&units=imperial

关于android - 开放天气图 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53329917/

相关文章:

android - 不是从 Activity 中调用 PICK_CONTACT Intent

c# - 上传捕获的图像进行解析(解析对象)

android - android中的新菜单?

angular - 无法对 openweathermap.org 执行看似简单的 HTTP POST

javascript - 无法从 Openweathermap API 获取温度

android - 一起使用 GridLayout 和 ConstraintLayout 时已经定义了属性 "orientation"

android - 无法使用新的 Android SDK 登录 Facebook?

android - 如何为工具栏溢出菜单图标制作动画

android - openOptionsMenu 功能在 ICS 中不起作用?

python - SlackAPI - 无法返回包含多个变量的消息