0
点赞
收藏
分享

微信扫一扫

OpenWeatherMap Current weather data

互联网码农 2023-07-27 阅读 63


http://openweathermap.org/current

Access current weather data for any location on Earth including over 200,000 cities! Current weather is frequently updated based on global models and data from more than 40,000 weather stations. Data is available in JSON, XML, or HTML format.


Call current weather data for one location

By city name

Description:

You can call by city name or city name and country code. API responds with a list of results that match a searching word.


API call:

api.openweathermap.org/data/2.5/weather?q={city name}

api.openweathermap.org/data/2.5/weather?q={city name},{country code}

Parameters:

q

Examples of API calls:

api.openweathermap.org/data/2.5/weather?q=London

api.openweathermap.org/data/2.5/weather?q=London,uk

By city ID

Description:

You can call by city ID. API responds with exact result.

List of city ID city.list.json.gz can be downloaded here http://bulk.openweathermap.org/sample/



We recommend to call API by city ID to get unambiguous result for your city.


Parameters:


id City ID

Examples of API calls:

api.openweathermap.org/data/2.5/weather?id=2172797

By geographic coordinates

API call:

api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}


Parameters:


lat, lon coordinates of the location of your interest

Examples of API calls:

api.openweathermap.org/data/2.5/weather?lat=35&lon=139

API respond:



{"coord":{"lon":139,"lat":35},
"sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049},
"weather":[{"id":804,"main":"clouds","description":"overcast clouds","icon":"04n"}],
"main":{"temp":289.5,"humidity":89,"pressure":1013,"temp_min":287.04,"temp_max":292.04},
"wind":{"speed":7.31,"deg":187.002},
"rain":{"3h":0},
"clouds":{"all":92},
"dt":1369824698,
"id":1851632,
"name":"Shuzenji",
"cod":200}



By ZIP code

API call:

api.openweathermap.org/data/2.5/weather?zip={zip code},{country code}


Examples of API calls:

api.openweathermap.org/data/2.5/weather?zip=94040,us

Parameters:

zip

API respond:



{"coord":{"lon":-122.09,"lat":37.39},
"sys":{"type":3,"id":168940,"message":0.0297,"country":"US","sunrise":1427723751,"sunset":1427768967},
"weather":[{"id":800,"main":"Clear","description":"Sky is Clear","icon":"01n"}],
"base":"stations",
"main":{"temp":285.68,"humidity":74,"pressure":1016.8,"temp_min":284.82,"temp_max":286.48},
"wind":{"speed":0.96,"deg":285.001},
"clouds":{"all":0},
"dt":1427700245,
"id":0,
"name":"Mountain View",
"cod":200}



Call current weather data for several cities

Cities within a rectangle zone

Description:

JSON returns the data from cities within the defined rectangle specified by the geographic coordinates.

Parameters:

bbox

callback

cluster

lang

Examples of API calls:


http://api.openweathermap.org/data/2.5/box/city?bbox=12,32,15,37,10&cluster=yes


Cities in cycle

Description:

JSON returns data from cities laid within definite circle that is specified by center point ('lat', 'lon') and expected number of cities ('cnt') around this point.

Parameters:

lat

lon

callback

cluster

lang

cnt

Examples of API calls:

http://api.openweathermap.org/data/2.5/find?lat=55.5&lon=37.5&cnt=10

Call for several city IDs

Parameters:


id City ID

Examples of API calls:

http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743&units=metric



Bulk downloading

Description:

As a standard we provide bulk of current weather for 20,000 cities, updated hourly. File name is weather_14.json.gz.

You can find this file in the list of bulk examples.

Other files in the list are examples of forecast. Please, read about them on the Forecast page.



Bulk downloading is available for not the all accounts. To get more information please refer to the price.



Examples of bulk files:

http://bulk.openweathermap.org/sample/



Weather parameters in API respond



If you do not see some of the parameters in your API respond it means that these weather phenomena are just not happened for the time of measurement for the city or location chosen. Only really measured or calculated data is displayed in API respond.



JSON

Example of API respond:



{"coord":
{"lon":145.77,"lat":-16.92},
"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],
"base":"cmc stations",
"main":{"temp":293.25,"pressure":1019,"humidity":83,"temp_min":289.82,"temp_max":295.37},
"wind":{"speed":5.1,"deg":150},
"clouds":{"all":75},
"rain":{"3h":3},
"dt":1435658272,
"sys":{"type":1,"id":8166,"message":0.0166,"country":"AU","sunrise":1435610796,"sunset":1435650870},
"id":2172797,
"name":"Cairns",
"cod":200}



Parameters:

coordcoord.loncoord.latweather

  •  (more info Weather condition codes)

weather.idweather.mainweather.descriptionweather.iconbasemainmain.tempmain.pressuremain.humiditymain.temp_minmain.temp_maxmain.sea_levelmain.grnd_levelwindwind.speedwind.degcloudsclouds.allrainrain.3hsnowsnow.3hdtsyssys.typesys.idsys.messagesys.countrysys.sunrisesys.sunsetidnamecod

XML

Example of API respond:



<current>
<city id="2643741" name="City of London">
 <coord lon="-0.09" lat="51.51"/>
 <country>GB</country>
 <sun rise="2015-06-30T03:46:57" set="2015-06-30T20:21:12"/>
</city>
<temperature value="72.34" min="66.2" max="79.88" unit="fahrenheit"/>
<humidity value="43" unit="%"/>
<pressure value="1020" unit="hPa"/>
<wind>
 <speed value="7.78" name="Moderate breeze"/>
 <direction value="140" code="SE" name="SouthEast"/>
</wind>
<clouds value="0" name="clear sky"/>
<visibility value="10000"/>
<precipitation mode="no"/>
<weather number="800" value="Sky is Clear" icon="01d"/>
<lastupdate value="2015-06-30T08:36:14"/>
</current>



Parameters:

citycity.id 
• City ID
city.namecity.coordcity.coord.loncity.coord.latcity.countrycity.suncity.sun.risecity.coord.settemperaturetemperature.valuetemperature.mintemperature.maxtemperature.unithumidityhumidity.value 
• Humidity value
humidity.unitpressurepressure.value 
• Pressure value
pressure.unitwindwind.speedwind.speed.value 
• Wind speed, mps
wind.speed.namewind.directionwind.direction.value 
• Wind direction, degrees (meteorological)
wind.direction.codewind.direction.namecloudsclouds.value 
• Cloudiness
clouds.namevisibilityvisibility.value 
• Visibility, meter
precipitationprecipitation.valueprecipitation.modeweatherweather.numberweather.valueweather.iconlastupdatelastupdate.value

List of weather condition codes

List of weather condition codes with icons (range of thunderstorm, drizzle, rain, snow, clouds, atmosphere including extreme conditions like tornado, hurricane etc.)



Min/max temperature in current weather API and forecast API



Please, do not confuse min/max parameters in current weather API and forecast API. In current weather API temp_min and temp_max are optional parameters mean min / max temperature in the city at the current moment to see deviation from current temp just for your reference. For large cities and megalopolises geographically expanded it might be applicable. In most cases both temp_min and temp_max parameters have the same volume as 'temp'. Please, use temp_min and temp_max



Example of current weather API respond:



"main":{
"temp":306.15, //current temperature 
"pressure":1013,
"humidity":44,
"temp_min":306, //min current temperature in the city
"temp_max":306 //max current temperature in the city
},



For comparison look at example of daily forecast weather API respond:


"dt":1406080800,
"temp":{
        "day":297.77,  //daily averaged temperature
        "min":293.52, //daily min temperature
        "max":297.77, //daily max temperature
        "night":293.52, //night temperature
        "eve":297.77, //evening temperature
        "morn":297.77}, //morning temperature



Other features

Format

Description:

JSON format is used by default. To get data in XML or HTML formats just set up mode = xml or html.

Parameters:

mode - possible values are xml and html. If mode parameter is empty the format is JSON by default.


Examples of API calls:

JSON api.openweathermap.org/data/2.5/weather?q=London

XML api.openweathermap.org/data/2.5/weather?q=London&mode=xml

HTML api.openweathermap.org/data/2.5/weather?q=London&mode=html

Search accuracy

Description:

You can use our geocoding system to find cities by name, country, zip-code or geographic coordinates. You can call also by part of the city name. To make the result more accurate just put the city name and country divided by comma.

To set the accuracy level either use the 'accurate' or 'like' type parameter. 'accurate' returns exact match values. 'like' returns results by searching for that substring. 



Call API by city ID instead of city name, city coordinates or zip code. In this case you get precise respond exactly for your city.



Parameters:

like

accurate

Examples of API calls:

Like api.openweathermap.org/data/2.5/find?q=London&type=like&mode=xml

Accurate api.openweathermap.org/data/2.5/find?q=London&type=accurate&mode=xml

Units format

Description:

Standard, metric, and imperial units are available.

Parameters:

units



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



Examples of API calls:

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

Multilingual support

Description:

You can use lang parameter to get the output in your language. We support the following languages that you can use with the corresponded lang values: English - en, Russian - ru, Italian - it, Spanish - es (or sp), Ukrainian - uk (or ua), German - de, Portuguese - pt, Romanian - ro, Polish - pl, Finnish - fi, Dutch - nl, French - fr, Bulgarian - bg, Swedish - sv (or se), Chinese Traditional - zh_tw, Chinese Simplified - zh (or zh_cn), Turkish - tr, Croatian - hr, Catalan - ca 

API call:

http://api.openweathermap.org/data/2.5/forecast/daily?id=524901&lang={lang}

Parameters:


lang language code

Examples of API calls:


http://api.openweathermap.org/data/2.5/forecast/daily?id=524901&lang=zh_cn


Call back function for JavaScript code

Description:

To use JavaScript code you can transfer callback functionName to JSONP callback. 

Examples of API calls:


api.openweathermap.org/data/2.5/weather?q=London,uk&callback=test



举报

相关推荐

0 条评论