YWeatherGetter4a Save

An Yahoo Weather API wrapper for android

Project README

YWeatherGetter4a


Note that YQL service is retired, so this lib don't work anymore :(


An Yahoo Weather API wrapper for android

An iOS version can be found here. https://github.com/zh-wang/YWeatherGetter4i

Works on android 2.3 or above.
Sample app can be found on Google Play.
https://play.google.com/store/apps/details?id=zh.wang.android.yweathergetter

Request and response elements are defined here.
https://developer.yahoo.com/weather/documentation.html#response

Check the XML structure returned by Yahoo Weather API here.
Sample Weather API Response - Shanghai

For more information, check Yahoo's document here.
Yahoo Weather.

  • Install

    compile 'zh.wang.android:yweathergetter4a:1.3.0'

  • How to use (Sample Activity)

    • Implement YahooWeatherInfoListener in your Activity. INTERNET and ACCESS_NETWORK_STATE permissions are required.

      @Override
      public void gotWeatherInfo(WeatherInfo weatherInfo, YahooWeather.ErrorType errorType) {
          if(weatherInfo != null) {
              // Add your code here
              // weatherInfo object contains all information returned by Yahoo Weather API
              // if `weatherInfo` is null, you can get the error from `errorType`
          }
      }
      
    • Get a instance of YahooWeather class.

      ```java
      YahooWeather mYahooWeather = YahooWeather.getInstance();
      ```
      
    • Query by place's name. You can replace cityAreaOrLocation to what you want. For example, "Tokyo Japan", "Acaraù Brazil", "Shanghai China", etc.

      ```java
      public void queryYahooWeatherByPlaceName(final Context context, final String cityAreaOrLocation, final YahooWeatherInfoListener result)
      ```
      
    • Query by latitude and longitude

      ```java
      public void queryYahooWeatherByLatLon(final Context context, final String lat, final String lon, final YahooWeatherInfoListener result)
      ```
      
    • Or use device's gps to detect current location. ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION is required.

      ```java
      public void queryYahooWeatherByGPS(final Context context, final YahooWeatherInfoListener result)
      ```
      
  • Other settings

    • You can set connect timeout and socket timeout by setConnectTimeout and setSocketTimeout. Or get the instance by getInstance(int connectTimeout, int socketTimeout).

    • If you use GPS position for query, the result WeatherInfo will contains an Address object, which is the detail address object return from Geocoder. It contains a lot of information but this lib only use locality, adminArea, and countryName by default. See YahooWeather.addressToPlaceName and Geocoder for details.

  • What kind of weather information can I get? You can get

Developed By

Zhenghong Wang - [email protected]

License

Copyright 2017 Zhenghong Wang

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Open Source Agenda is not affiliated with "YWeatherGetter4a" Project. README Source: zh-wang/YWeatherGetter4a
Stars
99
Open Issues
7
Last Commit
5 years ago

Open Source Agenda Badge

Open Source Agenda Rating