I am using the openweathermap.org api, and it provides me incorrect output.
If I hit this url, I get the 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 I call the same url via php curl
or file_get_contents
, I get the 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 are they different?
I don't see the problem. It returns the exact same values for longitude (-121.96
), latitude (37.83
), city ID (5342970
) and city name (Diablo
), which clearly indicates that both results represent results from the same location.
The minor differences between both results are probably caused by minor changes in the weather or results being taken from a different server or weather station (which the different values of the base
property seem to suggest).
I wouldn't bother about these minor differences. However, I do have another concern (see my note below).
The behavior of the zip
parameter is unreliable. When I open your URL in my browser from my location (in Belgium), I sometimes get the expected results and sometimes get this error :
{"cod":"404","message":"Error: Not found city"}
To avoid this problem, it's better to use one of the following options :
q
parameter, with city name and country as values :
http://api.openweathermap.org/data/2.5/weather?appid=35d3153a253e2536f49f02fd8080dfc2&q=Diablo,US
id
parameter, with your city ID as a value :
http://api.openweathermap.org/data/2.5/weather?appid=35d3153a253e2536f49f02fd8080dfc2&id=5342970
(You can download a list of all supported city IDs here)
lat
& lon
parameters, with your latitude and longitude as values :
http://api.openweathermap.org/data/2.5/weather?appid=35d3153a253e2536f49f02fd8080dfc2&lat=37.83&lon=-121.96
(You can also find the latitude and longitude of your city in this list of supported cities)
See the API docs for more details.