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.idWeather ID
    • weather.mainA set of weather parameters (rain, snow, extremes, etc.)
    • weather.descriptionWeather conditions within the group. You can get the output of your language.To learn more
    • weather.iconWeather Icon ID
  • Base Internal Parameters

  • main

    • main.tempThe temperature. Unit Default: Kelvin, Metric: Celsius, British: Fahrenheit.
    • main.feels_likeThe temperature. This temperature parameter describes human perception of the weather. Unit Default: Kelvin, Metric: Celsius, British: Fahrenheit.
    • main.pressureAtmospheric pressure (at sea level, if sea_level or GRND_level data is not available), hPa
    • main.humidityHumidity, %
    • main.temp_minCurrent lowest temperature. This is the lowest temperature ever observed (in large megacities and urban areas). Unit Default: Kelvin, Metric: Celsius, British: Fahrenheit.
    • main.temp_maxCurrent highest temperature. This is the highest temperature ever observed (in large megacities and urban areas). Unit Default: Kelvin, Metric: Celsius, British: Fahrenheit.
    • main.sea_levelAtmospheric pressure at sea level, hPa
    • main.grnd_levelSurface atmospheric pressure, hPa
  • wind

    • wind.speedThe wind speed. Unit Default value: m/s, metric: m/s, British: miles/hour.
    • wind.degWind direction, degree (meteorological)
    • wind.gustGust. Default unit: m/s, metric: m/s, British: miles/hour
  • clouds

    • clouds.allCloud cover, %
  • rain

    • rain.1hRainfall in the last hour, mm
    • rain.3hRainfall in the last 3 hours, mm
  • snow

    • snow.1hThe amount of snow in the last hour, millimeters
    • snow.3hThe amount of snow in the last 3 hours, millimeters
  • Dt data calculation time, Unix, UTC

  • sys

    • sys.typeInternal parameters
    • sys.idInternal parameters
    • sys.messageInternal parameters
    • sys.countryCountry code (GB, JP, etc)
    • sys.sunriseSunrise time, Unix, UTC
    • sys.sunsetSunset 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.