php - OpenWeatherMap API generates incorrect output -


i using openweathermap.org api, , provides me incorrect output.

if hit this url, following output :

"{"coord":{"lon":-121.96,"lat":37.83},"weather":[{"id":721,"main":"haze","description":"haze","icon":"50n"}],"base":"stations","main":{"temp":281.21,"pressure":1030,"humidity":81,"temp_min":273.15,"temp_max":285.15},"visibility":11265,"wind":{"speed":1.07,"deg":54.0019},"clouds":{"all":1},"dt":1454739836,"sys":{"type":1,"id":409,"message":0.0189,"country":"us","sunrise":1454771247,"sunset":1454809012},"id":5342970,"name":"diablo","cod":200}" 

if call same url via php curl or file_get_contents, following output :

"{"coord":{"lon":-121.96,"lat":37.83},"weather":[{"id":801,"main":"clouds","description":"few clouds","icon":"02n"}],"base":"cmc stations","main":{"temp":275.178,"pressure":1022.49,"humidity":83,"temp_min":275.178,"temp_max":275.178,"sea_level":1043.42,"grnd_level":1022.49},"wind":{"speed":1.07,"deg":356.501},"clouds":{"all":12},"dt":1454738179,"sys":{"message":0.0112,"country":"us","sunrise":1454771247,"sunset":1454809011},"id":5342970,"name":"diablo","cod":200}" 

why different?

i don't see problem. returns exact same values longitude (-121.96), latitude (37.83), city id (5342970) , city name (diablo), indicates both results represent results same location.

the minor differences between both results caused minor changes in weather or results being taken different server or weather station (which different values of base property seem suggest).

i wouldn't bother these minor differences. however, have concern (see note below).


note :

the behavior of zip parameter unreliable. when open url in browser location (in belgium), expected results , error :

{"cod":"404","message":"error: not found city"} 

to avoid problem, it's better use 1 of following options :

  • q parameter, city name , country values :

    http://api.openweathermap.org/data/2.5/weather?appid=35d3153a253e2536f49f02fd8080dfc2&q=diablo,us

  • id parameter, city id value :

    http://api.openweathermap.org/data/2.5/weather?appid=35d3153a253e2536f49f02fd8080dfc2&id=5342970
    (you can download list of supported city ids here)

  • lat & lon parameters, latitude , longitude values :

    http://api.openweathermap.org/data/2.5/weather?appid=35d3153a253e2536f49f02fd8080dfc2&lat=37.83&lon=-121.96
    (you can find latitude , longitude of city in this list of supported cities)

see the api docs more details.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -