zoukankan      html  css  js  c++  java
  • Login

    package com.baidu.baidulocationdemo;
    
    import com.baidu.location.LocationClient;
    import com.baidu.location.LocationClientOption;
    import com.baidu.location.LocationClientOption.LocationMode;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.EditText;
    import android.widget.RadioGroup;
    import android.widget.RadioGroup.OnCheckedChangeListener;
    import android.widget.TextView;
    
    public class LocationActivity extends Activity {
        private LocationClient mLocationClient;
    
        private TextView LocationResult, ModeInfor;
    
        private Button startLocation;
    
        private RadioGroup selectMode, selectCoordinates;
    
        private EditText frequence;
    
        private LocationMode tempMode = LocationMode.Hight_Accuracy;
    
        private String tempcoor = "gcj02";
    
        private CheckBox checkGeoLocation;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.location);
            mLocationClient = ((LocationApplication) getApplication()).mLocationClient;
    
            LocationResult = (TextView) findViewById(R.id.textView1);
            ModeInfor = (TextView) findViewById(R.id.modeinfor);
            ModeInfor.setText(getString(R.string.hight_accuracy_desc));
            ((LocationApplication) getApplication()).mLocationResult = LocationResult;
            frequence = (EditText) findViewById(R.id.frequence);
            checkGeoLocation = (CheckBox) findViewById(R.id.geolocation);
            startLocation = (Button) findViewById(R.id.addfence);
            startLocation.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    InitLocation();
    
                    if (startLocation.getText().equals(
                            getString(R.string.startlocation))) {
                        mLocationClient.start();
                        startLocation.setText(getString(R.string.stoplocation));
                    } else {
                        mLocationClient.stop();
                        startLocation.setText(getString(R.string.startlocation));
                    }
    
                }
            });
            selectMode = (RadioGroup) findViewById(R.id.selectMode);
            selectCoordinates = (RadioGroup) findViewById(R.id.selectCoordinates);
            selectMode.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    // TODO Auto-generated method stub
                    String ModeInformation = null;
                    switch (checkedId) {
                    case R.id.radio_hight:
                        tempMode = LocationMode.Hight_Accuracy;
                        ModeInformation = getString(R.string.hight_accuracy_desc);
                        break;
                    case R.id.radio_low:
                        tempMode = LocationMode.Battery_Saving;
                        ModeInformation = getString(R.string.saving_battery_desc);
                        break;
                    case R.id.radio_device:
                        tempMode = LocationMode.Device_Sensors;
                        ModeInformation = getString(R.string.device_sensor_desc);
                        break;
                    default:
                        break;
                    }
                    ModeInfor.setText(ModeInformation);
                }
            });
            selectCoordinates
                    .setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                        @Override
                        public void onCheckedChanged(RadioGroup group, int checkedId) {
                            // TODO Auto-generated method stub
                            switch (checkedId) {
                            case R.id.radio_gcj02:
                                tempcoor = "gcj02";
                                break;
                            case R.id.radio_bd09ll:
                                tempcoor = "bd09ll";
                                break;
                            case R.id.radio_bd09:
                                tempcoor = "bd09";
                                break;
                            default:
                                break;
                            }
                                                               }
                    });
        }
    
        @Override
        protected void onStop() {
            // TODO Auto-generated method stub
            mLocationClient.stop();
            super.onStop();
        }
    
        private void InitLocation() {
            LocationClientOption option = new LocationClientOption();
            option.setLocationMode(tempMode);//设置定位模式
            option.setCoorType(tempcoor);//返回的定位结果是百度经纬度,默认值gcj02
            int span = 1000;
            try {
                span = Integer.valueOf(frequence.getText().toString());
            } catch (Exception e) {
                // TODO: handle exception
            }
            option.setScanSpan(span);//设置发起定位请求的间隔时间为5000ms
            option.setIsNeedAddress(checkGeoLocation.isChecked());
            mLocationClient.setLocOption(option);
        }
    }
    

      

  • 相关阅读:
    day02操作系统/编程语言分类/python解释器介绍/python解释器多版本共存
    网络编程-互联网协议(网络编程)/基于TCP协议的套接字通信/加上通信循环/加上连接循环
    每天新的英语单词
    re模块(正则表达式)
    包的使用/time与datetime模块/random模块/打印进度条/shutil模块
    模块的使用之import/模块的使用之 from import/区分python文件的两种用途
    列表生成式与生成器表达式模块的使用模块的使用之from.......import区分python文件的两种用途文件的搜索路径
    三元表达式/函数的递归/匿名函数及其应用/map函数/reduce函数/ filter函数
    函数的嵌套/名称空间/作用域/函数对象/闭包函数
    跟未名学Office
  • 原文地址:https://www.cnblogs.com/jinglecode/p/4340691.html
Copyright © 2011-2022 走看看