百度天气预报接口api(百度天气预报接口API)

网友投稿 372 2023-02-04

本篇文章给大家谈谈百度天气预报接口api,以及百度天气预报接口API对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。 今天给各位分享百度天气预报接口api的知识,其中也会对百度天气预报接口API进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

如何使用百度天气预报API接口

百度API Key申请地址:http://lbsyun.baidu.com/apiconsole/key

创建应用 如图: 

提交后得到API Key 如图:

接口实例:http://api.map.baidu.com/telematics/v3/weather?location=南昌output=jsonak=你的API Keymcode=你的数字签名SHA1;com.example.administrator.jsontest(包名)

接口参数说明

参数类型

参数名称

是否必须

具体描述

String    location    true    输入城市名或经纬度,城市名如北京或者131,经纬度格式为lng,lat坐标,如:location=116.305145,39.982368;全国值为all,返回省会城市自治区,港澳台天气情况多城市天气预报中间用“|”分隔,如:location=116.305145,39.982368|123.342323,36238945|...  

String    output    false    输出的数据格式,默认为xml格式,当output设置为json时,输出的为json数据格式  

String    coord_type    false    请求参数坐标类型,默认为gcj02经纬度坐标。允许的值为bd09ll、bd09mc、gcj02、wgs84;  

返回的JSON数据

{
   "error":0,
   "status":"success",
   "date":"2016-03-05",
   "results":[
       {
           "currentCity":"北京",
           "pm25":"144",
           "index":[
               {
                   "title":"穿衣",
                   "zs":"较冷",
                   "tipt":"穿衣指数",
                   "des":"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。"},
               {
                   "title":"洗车",
                   "zs":"不宜",
                   "tipt":"洗车指数",
                   "des":"不宜洗车,未来24小时内有扬沙或浮尘,如果在此期间洗车,极易很快蒙上新的灰尘。"},
               {
                   "title":"旅游",
                   "zs":"一般",
                   "tipt":"旅游指数",
                   "des":"风稍大,扬沙或浮尘天气对能见度和空气质量都会有些影响,出行请注意交通安全和采取适当的防尘措施。"},
               {
                   "title":"感冒",
                   "zs":"易发",
                   "tipt":"感冒指数",
                   "des":"昼夜温差大,风力较强,易发生感冒,请注意适当增减衣服,加强自我防护避免感冒。"},
               {
                   "title":"运动",
                   "zs":"较不宜",
                   "tipt":"运动指数",
                   "des":"有扬沙或浮尘,建议适当停止户外运动,选择在室内进行运动,以避免吸入更多沙尘,有损健康。"},
               {
                   "title":"紫外线强度",
                   "zs":"最弱",
                   "tipt":"紫外线强度指数",
                   "des":"属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。"}
          ],
 "weather_data":[
             {
                 "date":"周六 03月05日 (实时:12℃)",              "dayPictureUrl":"http://api.map.baidu.com/images/weather/day/fuchen.png",
   "nightPictureUrl":"http://api.map.baidu.com/images/weather/night/qing.png",
                 "weather":"浮尘转晴",
                 "wind":"北风4-5级",
                 "temperature":"12 ~ -1℃"},
 {
                 "date":"周日",
"dayPictureUrl":"http://api.map.baidu.com/images/weather/day/duoyun.png",
"nightPictureUrl":"http://api.map.baidu.com/images/weather/night/duoyun.png",
                 "weather":"多云",
                 "wind":"微风",
                 "temperature":"10 ~ -3℃"},
 {
                 "date":"周一",            "dayPictureUrl":"http://api.map.baidu.com/images/weather/day/duoyun.png",
"nightPictureUrl":"http://api.map.baidu.com/images/weather/night/yin.png",
                 "weather":"多云转阴",
                 "wind":"微风",
                 "temperature":"13 ~ 2℃"},
 {
                 "date":"周二",                "dayPictureUrl":"http://api.map.baidu.com/images/weather/day/yin.png",
"nightPictureUrl":"http://api.map.baidu.com/images/weather/night/duoyun.png",
             "weather":"阴转多云",
             "wind":"北风3-4级",
             "temperature":"6 ~ -1℃"}
 ]}]}

3.  我们来写个demo,代码如下:

package com.example.administrator.jsontest;
public class MainActivity extends Activity {
   private Button button;
   private TextView textView;
   private Handler handler = new Handler() {
       @Override
       public void handleMessage(Message msg) {
           switch (msg.what) {
               case 0:
                   String re = (String) msg.obj;
                   textView.setText(re);
                   break;
           }
       }
   };
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       button = (Button) findViewById(R.id.button);
       textView = (TextView) findViewById(R.id.textView);
       button.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Log.i("TAG", "点击了Button");
               sendRequestWithHttpClient();
           }
       });
   }
   private void sendRequestWithHttpClient() {
       new Thread(new Runnable() {
           @Override
           public void run() {
               HttpURLConnection connection = null;
               try {
                   URL url = new URL("http://api.map.baidu.com/telematics/v3/weather?location=南昌output=jsonak=8ixCCFzlBB617YX7tONI2P5Bmcode=1C:6B:42:33:E8:A6:DC:A2:11:6E:26:EC:84:BD:42:E3:8E:6B:57:9A;com.example.administrator.jsontest");
                   connection = (HttpURLConnection) url.openConnection();
                   connection.setRequestMethod("GET");
                   connection.setConnectTimeout(5000);
                   connection.setReadTimeout(5000);
                   InputStream in = connection.getInputStream();
                   BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                   StringBuilder response = new StringBuilder();
                   String line;
                   while ((line = reader.readLine()) != null) {
                       response.append(line);
                   }
                   Log.i("TAG", response.toString());                    parseJSONObjectOrJSONArray(response.toString());
               } catch (MalformedURLException e) {
                   e.printStackTrace();
               } catch (IOException e) {
                   e.printStackTrace();
               }
           }
       }).start();
   }
   //解析JSON数据
   private void parseJSONObjectOrJSONArray(String jsonData) {
       try {
           String count = "";
           JSONObject jsonObject = new JSONObject(jsonData);
           JSONArray jsonArray = jsonObject.getJSONArray("results");
           if (jsonArray.length() 0) {
               JSONObject object = jsonArray.getJSONObject(0);
               String city = object.optString("currentCity");
               JSONArray array = object.getJSONArray("weather_data");
               for (int i = 0; i < array.length(); i++) {
                   JSONObject jsonObject1 = array.getJSONObject(i);
                   String dateDay = jsonObject1.optString("date");
                   String weather = jsonObject1.optString("weather");
                   String wind = jsonObject1.optString("wind");
                   String temperature = jsonObject1.optString("temperature");
                   count =count +"\n"+ dateDay + " " + weather + " " + wind + " " + temperature;
                   Log.i("AAA",count);
               }
               Message message = new Message();
               message.what = 0;
               message.obj = count;
               handler.sendMessage(message);
           }
       } catch (JSONException e) {
           e.printStackTrace();
       }
   }
}


4. 运行结果如下:

天气预报API接口是什么?

天气预报API接口是气象服务商为客户提供服务的唯一接口。拿墨迹赤必为例,跟客户充分沟通后了解客户的实际需求,从而对现有的数据进行调整,符合客户的需求形成API接口,让客户接入,这样就形成了一个完整的服务。所以说API接口并不是一个很神秘的东西,只不过是企业和客户之间的一条服务纽带。

api接口是什么意思?

是指同一计算机不同功能层之间的通信规则称为接口。
java接口作用:
1、利于代码的规范。这样做的目的一方面是为了给开发人员一个清晰的指示百度天气预报接口api,告诉百度天气预报接口api他们哪些业务需要实现;同时也能防止由于开发人员随意命名而导致的命名不清晰和代码混乱,影响开发效率。
2、有利于对代码进行维护。可以一开始定义一个接口,把功能菜单放在接口里,然后定义类时实现这个接口,以后要换的话只不过是引用另一个类而已,这样就达到维护、拓展的方便性。
3、保证代码的安全和严密。一个好的程序一定符合高内聚低耦合的特征,能够让系统的功能较好地实现,而不涉及任何具体的实现细节。这样就比较安全、严密一些,这一思想一般在软件开发中较为常见。

如何使用PHP调用API接口实现天气查询功能

最近在做微信公众平台测试时,想在里面子菜单上添加查询未来几天(包括今天)天气的功能,就查找了下好用的天气预报查询接口API,使用比较多的有:国家气象局天气接口、新浪天气预报接口、百度天气预报接口、google天气接口、Yahoo天气接口等等,我使用的是百度提供的免费天气查询接口API,下面与大家分享下...

1、查询方式:

百度提供的是根据纬度和城市名查询天气情况

2、接口事例:

3、接口参数说明:


4、返回结果说明:


5、

//城市名

$city = '上海';

//对json格式的字符串进行编码

$arr =json_decode($str,TRUE);

print_r($atr);

//城市名
   $city = '上海';
 
   //获取json格式的数据
   $str =file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=".$city."output=jsonak=5slgyqGDENN7Sy7pw29IUvrZ");

   //对json格式的字符串进行编码
   $arr =json_decode($str,TRUE);      

   print_r($atr);

6、返回页面的是json编码后的数据:

[plain] view plain copy print?

<meta charset="UTF-8"

Array

(

[error] = 0

[status] = success

[date] = 2014-03-17

[results] = Array

(

[0] = Array

(

[currentCity]= 上海

[weather_data]= Array

(

[0]= Array

(

[date] = 周一(今天, 实时:19℃)

[dayPictureUrl] =http://api.map.baidu.com/images/weather/day/qing.png

[nightPictureUrl] =http://api.map.baidu.com/images/weather/night/qing.png

[weather] = 晴

[wind] = 西南风3-4级

[temperature] = 13℃

)

[1] = Array

(

[date]= 周二

[dayPictureUrl] =http://api.map.baidu.com/images/weather/day/duoyun.png

[nightPictureUrl] = http://api.map.baidu.com/images/weather/night/yin.png

[weather]= 多云转阴

[wind]= 东北风3-4级

[temperature] = 24 ~ 9℃

)

[2] = Array

(

[date]= 周三

[dayPictureUrl] =http://api.map.baidu.com/images/weather/day/zhongyu.png

[nightPictureUrl] = http://api.map.baidu.com/images/weather/night/xiaoyu.png

[weather]= 中雨转小雨

[wind]= 东北风3-4级

[temperature] = 15 ~ 8℃

)

[3] = Array

(

[date]= 周四

[dayPictureUrl] =http://api.map.baidu.com/images/weather/day/duoyun.png

[nightPictureUrl] =http://api.map.baidu.com/images/weather/night/qing.png

[weather]= 多云转晴

[wind]= 北风3-4级

[temperature] = 14 ~ 6℃

)

)

)

)

)

<meta charset="UTF-8"
Array
(
   [error] = 0
   [status] = success
   [date] = 2014-03-17
   [results] = Array
       (
           [0] = Array
               (
                   [currentCity]= 上海
                   [weather_data]= Array
                       (
                           [0]= Array
                               (
                                  [date] = 周一(今天, 实时:19℃)
                                  [dayPictureUrl] =http://api.map.baidu.com/images/weather/day/qing.png
                                  [nightPictureUrl] =http://api.map.baidu.com/images/weather/night/qing.png
                                   [weather] = 晴
                                  [wind] = 西南风3-4级
                                  [temperature] = 13℃
                               )

                           [1] = Array
                               (
                                   [date]= 周二
                                  [dayPictureUrl] =http://api.map.baidu.com/images/weather/day/duoyun.png
                                  [nightPictureUrl] = http://api.map.baidu.com/images/weather/night/yin.png
                                   [weather]= 多云转阴
                                   [wind]= 东北风3-4级
                                  [temperature] = 24 ~ 9℃
                               )

                           [2] = Array
                               (
                                   [date]= 周三
                                  [dayPictureUrl] =http://api.map.baidu.com/images/weather/day/zhongyu.png
                                  [nightPictureUrl] = http://api.map.baidu.com/images/weather/night/xiaoyu.png
                                   [weather]= 中雨转小雨
                                   [wind]= 东北风3-4级
                                  [temperature] = 15 ~ 8℃
                               )

                           [3] = Array
                               (
                                   [date]= 周四
                                  [dayPictureUrl] =http://api.map.baidu.com/images/weather/day/duoyun.png
                                   [nightPictureUrl] =http://api.map.baidu.com/images/weather/night/qing.png
                                   [weather]= 多云转晴
                                   [wind]= 北风3-4级
                                  [temperature] = 14 ~ 6℃
                               )

                       )

               )

       )

)

7、PHP中自带了处理json格式字符串的内置函数,下面做一个事例,并给出完整代码:

[php] view plain copy print?

<metacharset="UTF-8"

<?php

//城市名

$city = '上海';

//获取json格式的数据

$str = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=".$city."output=jsonak=5slgyqGDENN7Sy7pw29IUvrZ");

//对json格式的字符串进行编码

$arr = json_decode($str,TRUE);

echo "城市:".$arr['results'][0]['currentCity']." 日期:".$arr['date']."<br /<br /";

foreach($arr['results'][0]['weather_data']as $val)

{

echo $val['date']."<br/";

echo "天气:{$val['weather']}<br/";

echo "风向:{$val['wind']}<br/";

echo "温度:{$val['temperature']}<br/<br /";

}

?

<metacharset="UTF-8"
<?php
   //城市名
   $city = '上海';
 
   //获取json格式的数据
   $str = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=".$city."output=jsonak=5slgyqGDENN7Sy7pw29IUvrZ");

   //对json格式的字符串进行编码
   $arr = json_decode($str,TRUE);      

   echo "城市:".$arr['results'][0]['currentCity']." 日期:".$arr['date']."<br /<br /";

   foreach($arr['results'][0]['weather_data']as $val)
   {
       echo $val['date']."<br/";
       echo "天气:{$val['weather']}<br/";
       echo "风向:{$val['wind']}<br/";
       echo "温度:{$val['temperature']}<br/<br /";
   }
?

8、返回的内容如下:


各种API接口网址

http://doc.tuling123.com/openapi2/263611

http://lbsyun.baidu.com/index.php?title=webapi

http://ai.baidu.com/
涵盖图像处理、自然语言、语音技术、知识图谱、数据智能、AR、视频技术和深度学习八大方面。看需选择即可。

http://www.faceplusplus.com.cn/
注:申请试用的API Key可以免费试用他上面的接口

手机号码归属地API接口: https://www.juhe.cn/docs/api/id/11
历史上的今天API接口: https://www.juhe.cn/docs/api/id/63
股票数据API接口: https://www.juhe.cn/docs/api/id/21
全国WIFI接口: https://www.juhe.cn/docs/api/id/18
星座运势接口: https://www.juhe.cn/docs/api/id/58
黄金数据接口: https://www.juhe.cn/docs/api/id/29
语音识别接口: https://www.juhe.cn/docs/api/id/134
周公解梦接口: https://www.juhe.cn/docs/api/id/64
天气预报API接口: https://www.juhe.cn/docs/api/id/73
身份证查询API接口: https://www.juhe.cn/docs/api/id/38
笑话大全API接口: https://www.juhe.cn/docs/api/id/95
邮编查询接口: https://www.juhe.cn/docs/api/id/66
老黄历接口: https://www.juhe.cn/docs/api/id/65
网站安全检测接口: https://www.juhe.cn/docs/api/id/19
手机固话来电显示接口: https://www.juhe.cn/docs/api/id/72
基金财务数据接口: https://www.juhe.cn/docs/api/id/28
成语词典接口: https://www.juhe.cn/docs/api/id/157
新闻头条接口: https://www.juhe.cn/docs/api/id/235
IP地址接口: https://www.juhe.cn/docs/api/id/1
问答机器人接口: https://www.juhe.cn/docs/api/id/112
汇率API接口: https://www.juhe.cn/docs/api/id/80
电影票房接口: https://www.juhe.cn/docs/api/id/44
万年历API接口: https://www.juhe.cn/docs/api/id/177
NBA赛事接口: https://www.juhe.cn/docs/api/id/92

https://developers.douban.com/wiki/?title=guide

淘宝开放平台 http://open.taobao.com/?spm=a219a.7395905.1.1.YdFDV6

微博开放平台 http://open.weibo.com/wiki/API

讯飞语音 http://www.xfyun.cn/robots/solution
马化腾的微信开放平台(对应的还有腾讯开放平台)
https://open.weixin.qq.com/
融云IM https://developer.rongcloud.cn/signin?returnUrl=%2Fapp%2Fappkey%2FPv4vYQwaxSZdfpLX5AI%3D
高德地图 http://lbs.amap.com/

天气预报API接口是可以定制的吗?

其他百度天气预报接口api的我不太了解百度天气预报接口api,应该是也可以的百度天气预报接口api,但是我们合作的墨迹赤必我是可以确定是可以的。因为我们是做新零售的百度天气预报接口api,部分产品的属性跟天气是有很大关联的。我们在跟墨迹赤必沟通后,他们根据我们的需求专门对我们开发了定制的API接口。这里边的气象数据。可以结合产品的属性,长周期关联分析,为我们提供合理的备货与库存压力预测。所以说百度天气预报接口api你们如果有需求的话可以跟那边联系。 关于百度天气预报接口api和百度天气预报接口API的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。 百度天气预报接口api的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于百度天气预报接口API、百度天气预报接口api的信息别忘了在本站进行查找喔。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:百度云api接口(百度云接口怎么调用)
下一篇:百度搜索接口api(百度搜索接口)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~