打开天气图 API

OpenWeatherMap API

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

menu.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>

MainActivity.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 link 如果需要,可获得更深入的视图

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