preface
I have obtained weather data before, displayed it in the front end, checked some third-party support, and then used OpenWeather. In this record to share, for your reference.
(I am Java after midnight, in nuggets this share experience, those who rely on copy of the handling of the author, without permission, do not copy the article)
Benefits: free enough to use, simple mailbox registration can, not enough to register ten key, logic cycle in the code to use. Disadvantages: entry is the name of the city, some will not query, query can only go some of the bottom strategy.
Interface Support Description
Here’s a screenshot of the translation:
Let’s take a look at the current weather
The current weather
By geographic coordinates
Api.openweathermap.org/data/2.5/weather?lat= {lat} & lon = {lon} & appid = [{API key}] (https://home.openweathermap.org/api_keys)
According to the city ID
Api.openweathermap.org/data/2.5/weather?id=} {city id appid = [{API key}] (https://home.openweathermap.org/api_keys) The city ID can be downloaded directly from his place
Of course you can support batch.
Returns the object
Focus on the returned data structure:
{" coord ": {" lon" : 122.08, "lat" : 37.39}, "weather" : [{" id ": 800," main ":" Clear ", "description" : "The clear sky", "icon" : "01 d"}], "the base", "crisis", "main" : {" temp ": 282.55," feels_like ": 281.86," temp_min ": "Limit ": {" limit ": {" limit ": {" limit ": {" limit ": {" limit ": {" limit ": {" limit ": {" limit ": { 350}, "clouds" : {" all ": 1}," dt ": 1560350645," sys ": {" type" : 1, "id" : 5122, the "message" : 0.0139, "country" : "US", "sunrise": 1560343627, "sunset": 1560396563 }, "timezone": -25200, "id": 420006353, "name": "Mountain View", "cod": 200 }Copy the code
Focus on the description, the intuition to see if it works for you
“`- coord
- 'coord.lon' City location, longitude - 'coord.lat' city location, latitudeCopy the code
-
Weather (Code for weather conditions for more information)
weather.id
Weather IDweather.main
A set of weather parameters (rain, snow, extremes, etc.)weather.description
Weather conditions within the group. You can get the output of your language.To learn moreweather.icon
Weather Icon ID
-
Base Internal Parameters
-
main
main.temp
The temperature. Unit Default: Kelvin, Metric: Celsius, British: Fahrenheit.main.feels_like
The temperature. This temperature parameter describes human perception of the weather. Unit Default: Kelvin, Metric: Celsius, British: Fahrenheit.main.pressure
Atmospheric pressure (at sea level, if sea_level or GRND_level data is not available), hPamain.humidity
Humidity, %main.temp_min
Current lowest temperature. This is the lowest temperature ever observed (in large megacities and urban areas). Unit Default: Kelvin, Metric: Celsius, British: Fahrenheit.main.temp_max
Current highest temperature. This is the highest temperature ever observed (in large megacities and urban areas). Unit Default: Kelvin, Metric: Celsius, British: Fahrenheit.main.sea_level
Atmospheric pressure at sea level, hPamain.grnd_level
Surface atmospheric pressure, hPa
-
wind
wind.speed
The wind speed. Unit Default value: m/s, metric: m/s, British: miles/hour.wind.deg
Wind direction, degree (meteorological)wind.gust
Gust. Default unit: m/s, metric: m/s, British: miles/hour
-
clouds
clouds.all
Cloud cover, %
-
rain
rain.1h
Rainfall in the last hour, mmrain.3h
Rainfall in the last 3 hours, mm
-
snow
snow.1h
The amount of snow in the last hour, millimeterssnow.3h
The amount of snow in the last 3 hours, millimeters
-
Dt data calculation time, Unix, UTC
-
sys
sys.type
Internal parameterssys.id
Internal parameterssys.message
Internal parameterssys.country
Country code (GB, JP, etc)sys.sunrise
Sunrise time, Unix, UTCsys.sunset
Sunset time, Unix, UTC
-
Timezone Offset in seconds from UTC
-
Id City ID
-
Name City name
-
Cod internal parameters
The code logic called:Copy the code
HttpResponse<String> stringHttpResponse = Unirest.get(weatherUrl + "/weather").queryString("lang", lang).queryString("units", units).queryString("q", city).queryString("appid", weatherKey).asString();
String body = stringHttpResponse.getBody();
Copy the code
conclusion
This third party weather can still meet daily needs, especially if it is global.