douge7771 2016-02-06 07:06
浏览 91

OpenWeatherMap API生成错误的输出

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?

  • 写回答

1条回答 默认 最新

  • duanjigua5753 2016-03-11 08:15
    关注

    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).


    Note :

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据