通过高德地图API定位并获取天气信息

如何申请KEY自行百度,注意SHA1和包名一定要对上.
高德SDK包下载地址:http://download.csdn.net/detail/switch2010/8264611

1.实现AMapLocalWeatherListener接口,并重写onWeatherLiveSearched,onWeatherForecaseSearched方法

public class WeatherExecutor implements AMapLocalWeatherListener{

public WeatherExecutor() {
        //在初始化时,执行定位并获取天气
        LocationManagerProxy mLocationManagerProxy = LocationManagerProxy.getInstance(mContext);
        mLocationManagerProxy.requestWeatherUpdates(LocationManagerProxy.WEATHER_TYPE_LIVE, this);
    }


//实时天气
 @Override
public void onWeatherLiveSearched(AMapLocalWeatherLive aMapLocalWeatherLive) {
  if (aMapLocalWeatherLive != null && aMapLocalWeatherLive.getAMapException().getErrorCode() == 0) {

      //天气信息都保存在AmapLocalWeatherLive中

      //风向
      aMapLocalWeatherLive.getWindDir();

      //风力
      aMapLocalWeatherLive.getWindPower();

      //湿度
      aMapLocalWeatherLive.getHumidity();

     //天气现象表(天气现象表看下方)
     aMapLocalWeatherLive.getWeather();

     //定位的城市名称
     aMapLocalWeatherLive.getCity();

   } else {
            Log.e(TAG, "获取天气预报失败");
        }

  }

//预报天气
    @Override
    public void onWeatherForecaseSearched(AMapLocalWeatherForecast aMapLocalWeatherForecast) {

    }
}

天气现象表


多云

阵雨
雷阵雨
雷阵雨并伴有冰雹
雨夹雪
小雨
中雨
大雨
暴雨
大暴雨
特大暴雨
阵雪
小雪
中雪
大雪
暴雪

冻雨
沙尘暴
小雨-中雨
中雨-大雨
大雨-暴雨
暴雨-大暴雨
大暴雨-特大暴雨
小雪-中雪
中雪-大雪
大雪-暴雪
浮尘
扬沙
强沙尘暴

龙卷风
弱高吹雪
轻霾

你可能感兴趣的:(安卓踩坑日记)