Android Baidu Weather Interface

Source: Internet
Author: User

Baidu provides weather forecast query interface API, can be based on latitude/longitude/city Name query weather conditions.

Interface description

Search for weather results based on latitude/longitude/city name

interface Example
Http://api.map.baidu.com/telematics/v3/weather?location= Beijing &output=json&ak=yourkey
Baidu AK Application address:  Http://lbsyun.baidu.com/apiconsole/key
After the AK application, you can use this interface directly.
Interface parameter Description
parameter Type Parameter name whether you must Specific Description
String Ak True Developer Key
String sn False This parameter must be used if the user is using the AK Check mode for SN check.
String Location True Enter city or latitude and longitude, city name such as: Beijing, latitude format for Lng,lat coordinates such as: location=116.305145,39.982368; City weather Forecast Middle "|" Separate, location=116.305145,39.982368| 122.305145,36.982368| ....
String Output False The output data format, the default is the XML format, when output is set to ' JSON ', outputs the data in JSON format;
String Coord_type False The request parameter coordinate type, which defaults to gcj02 latitude and longitude coordinates. The allowed values are BD09LL, BD09MC, gcj02, WGS84. Bd09ll said Baidu latitude and longitude coordinates, BD09MC said Baidu Mercator coordinates, GCJ02 said after the National Bureau encrypted coordinates. WGS84 represents the coordinates acquired by GPS.
return results
Parameter name meaning Description
CurrentCity Current City Return to city name
Status Return result status information
Date Current time Year-month-day
Results Weather forecast Information Day can return to the recent 3 days of weather conditions (today, tomorrow, the day after yesterday), evening can return to the last 4 days of the weather conditions (today, tomorrow, the day after, the day after Tomorrow)
Results.currentcity Current City
Results.weather_data Weather_data.date Weather forecast Time
Weather_data.daypictureurl Daytime weather forecast Picture URL
Weather_data.nightpictureurl Night weather forecast Picture URL
Weather_data.weather Weather conditions All weather conditions ("|" Separator): Sunny | cloudy | overcast | showers | thunderstorms | Thunderstorms with hail | sleet | rain | cloudy | heavy rain | rainstorm | heavy Rainstorm | snow | Snow | snow | blizzard | fog | freezing Rain | sandstorm | Drizzle to moderate rain | Rain to heavy rains | Rainstorm to heavy rain | Rainstorm to torrential rain | Snow turn snow | Snow to Snow |
Weather_data.wind Wind
Weather_data.temperature Temperature
2. Viewing data interface data on a Web page
Data in XML format:
1 <?XML version= "1.0" encoding= "Utf-8"?> 2 <Cityweatherresponse>3     <Status>Success</Status>4     <Date>2014-05-03</Date>5     <Results> 6      7         <currentcity>Beijing</currentcity>8         <Weather_data>9                             <Date>Saturday (Today, Real time: 22 ℃)</Date>Ten                 <Daypictureurl>Http://api.map.baidu.com/images/weather/day/leizhenyu.png</Daypictureurl> One                 <Nightpictureurl>Http://api.map.baidu.com/images/weather/night/duoyun.png</Nightpictureurl> A                 <Weather>Thundershowers to Cloudy</Weather> -                 < Wind>North Wind Level 5-6</ Wind> -                 <Temperature>24 ~ 11 ℃</Temperature> the                             <Date>Sunday</Date> -                 <Daypictureurl>Http://api.map.baidu.com/images/weather/day/duoyun.png</Daypictureurl> -                 <Nightpictureurl>Http://api.map.baidu.com/images/weather/night/qing.png</Nightpictureurl> -                 <Weather>Cloudy With a sunny turn</Weather> +                 < Wind>North Wind Level 4-5</ Wind> -                 <Temperature>19 ~ 8 ℃</Temperature> +                             <Date>Monday</Date> A                 <Daypictureurl>Http://api.map.baidu.com/images/weather/day/qing.png</Daypictureurl> at                 <Nightpictureurl>Http://api.map.baidu.com/images/weather/night/qing.png</Nightpictureurl> -                 <Weather>Clear</Weather> -                 < Wind>Breeze</ Wind> -                 <Temperature>21 ~ 9 ℃</Temperature> -                             <Date>Tuesday</Date> -                 <Daypictureurl>Http://api.map.baidu.com/images/weather/day/duoyun.png</Daypictureurl> in                 <Nightpictureurl>Http://api.map.baidu.com/images/weather/night/qing.png</Nightpictureurl> -                 <Weather>Cloudy With a sunny turn</Weather> to                 < Wind>Breeze</ Wind> +                 <Temperature>21 ~ 10 ℃</Temperature> -                     </Weather_data> the         </Results> * </Cityweatherresponse>
Data in JSON form:
{"Error": 0, "status": "Success", "date": "2014-05-03", "results": [{"currentcity": "Beijing", "Weather_data": [{"Date": "Saturday (Today, Live: 22 ℃)", "Daypicture Url ":" Http://api.map.baidu.com/images/weather/day/leizhenyu.png "," Nightpictureurl ":" Http://api.map.b                    Aidu.com/images/weather/night/duoyun.png "," Weather ":" Thundershowers to Cloudy "," Wind ":" North 5-6 Level ",                    "Temperature": "24 ~ 11 ℃"}, {"Date": "Sunday", "Daypictureurl": "Http://api.map.baidu.com/images/weather/day/duoyun.png", "Nightpictureurl": " Http://api.map.baidu.com/images/weather/night/qing.png "," Weather ":" Cloudy Turn Clear "," Wind ":                    "North Wind Level 4-5", "Temperature": "19 ~ 8 ℃"}, {"Date": "Monday", "DaypIctureurl ":" Http://api.map.baidu.com/images/weather/day/qing.png "," Nightpictureurl ":" Http://api.map.                    Baidu.com/images/weather/night/qing.png "," Weather ":" Sunny "," wind ":" Breeze ", "Temperature": "21 ~ 9 ℃"}, {"Date": "Tuesday", "Da Ypictureurl ":" Http://api.map.baidu.com/images/weather/day/duoyun.png "," Nightpictureurl ":" Http://api.                    Map.baidu.com/images/weather/night/qing.png "," Weather ":" Cloudy to clear "," wind ":" Breeze ", "Temperature": "21 ~ 10 ℃"}]}]}

The following is a demo to get the weather data (in order to get JSON, for example, do not parse):
Data obtained on the phone: part of the Code:
1  Public classMainactivityextendsActivity {2 3     PrivateTextView Showtextview;4 5     Privateasynchttpclient masynchttpclient;6 7     PrivateString URL = "Your Baidu Weather Interface";8 9 @OverrideTen     protected voidonCreate (Bundle savedinstancestate) { One         Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.activity_main); -  -Showtextview =(TextView) Findviewbyid (R.id.showtextview); the  -Masynchttpclient =Newasynchttpclient (); -  -Masynchttpclient.get (URL,NULL,NewJsonhttpresponsehandler () { +  - @Override +              Public voidonsuccess (jsonobject result) { A                 Super. onsuccess (result); at  - Showtextview.settext (result.tostring ()); -             } -  - @Override -              Public voidonfinish () { in                 //TODO auto-generated Method Stub -                 Super. OnFinish (); to             } +  -         }); the  *     } $}

Android Baidu Weather Interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.