基于百度定位获取当前城市请求天气信息

本文介绍了一个小实例,展示如何结合百度定位SDK获取当前城市,并利用聚合数据提供的天气API来请求和展示实时天气信息。包括获取城市、发送位置请求以及解析和展示天气数据的过程。
摘要由CSDN通过智能技术生成

这里写图片描述

一个简单易懂的小例子。用到的知识点。

1.基于百度定位SDK获取当前城市

2.使用聚合数据提供的天气信息API

3.异步发送位置信息请求天气数据

百度定位SDK的使用不再详细介绍,参考百度地图提供的资料很容易配置。给出百度地图定位SDK用法连接。http://lbsyun.baidu.com/index.php?title=android-locsdk/guide/key

在代码中详细介绍

public class MainActivity extends AppCompatActivity {
   
    public LocationClient mLocationClient = null;
    public BDLocationListener myListener = new MyLocationListener();
    TextView textView;
    String mCity = "";//存放当前城市
    String mCurrentLocation = "";//当前位置信息

    String mTem = "";//当前温度

    TextView mCitytv;//显示城市
    TextView mWeathertv;//显示天气
    TextView mTemtv;//显示温度

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
                //绑定控件
        findview();
                //获取位置
        getLocation();
    }

    private void findview() {
        mCitytv = (TextView) findViewById(R.id.x_CurrentCity);
        mWeathertv = (TextView) findViewById(R.id.x_CurrentWeather);
        mTemtv = (TextView) findViewById(R.id.x_CurrentTem);
    }

/*
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle bundle = msg.getData();
            String location = bundle.getString("位置");
            //将位置传入异步线程中请求天气信息
            new ASyncUploadImage().execute(location);
        }
    };
*/

    private void getLocation() {
        //获取地理位置管理器
        mLocationClient = new LocationClient(getApplicationContext());     //声明LocationClient类
        initLocation();
        mLocationClient.registerLocationListener(myListener);    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值