1 package com.aihunqin.test; 2  3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.widget.TextView; 6  7 import com.baidu.location.BDLocation; 8 import com.baidu.location.BDLocationListener; 9 import com.baidu.location.LLSInterface;10 import com.baidu.location.LocationClient;11 import com.baidu.location.LocationClientOption;12 import com.baidu.location.LocationClientOption.LocationMode;13 import com.example.aihunqin.R;14 15 public class BaiduLocation extends Activity {16     public LocationClient mLocationClient;17     public MyLocationListener mMyLocationListener;18     public TextView mLocationResult;19 20     @Override21     protected void onCreate(Bundle savedInstanceState) {22 23         super.onCreate(savedInstanceState);24         mLocationClient = new LocationClient(getApplicationContext());25         mMyLocationListener = new MyLocationListener();26         mLocationClient.registerLocationListener(mMyLocationListener);27         setContentView(R.layout.baidulocation);28         mLocationResult = (TextView) findViewById(R.id.mLocationResult);29         InitLocation();30         mLocationClient.start();31     }32 33     /**34      * 实现定位回调监听35      * 36      * @author Alex37      * 38      */39     public class MyLocationListener implements BDLocationListener {40 41         @Override42         public void onReceiveLocation(BDLocation location) {43             // Receive Location44             StringBuffer sb = new StringBuffer(256);45             sb.append("time:");46             sb.append(location.getTime());47             sb.append("\nerror code:");48             sb.append(location.getLocType());49             sb.append("\nlatitude:");50             sb.append(location.getLatitude());51             sb.append("\nlontitude:");52             sb.append(location.getLongitude());53             sb.append("\nradius:");54             sb.append(location.getRadius());55             if (location.getLocType() == BDLocation.TypeNetWorkLocation) {56                 sb.append("\naddr:");57                 sb.append(location.getAddrStr());58                 // 运营商信息59                 sb.append("\noperationers:");60                 sb.append(location.getOperators());61             }62             logMsg(sb.toString());63         }64     }65 66     /**67      * 显示请求你字符串68      * 69      * @param str70      */71     public void logMsg(String str) {72         try {73             if (mLocationResult != null)74                 mLocationResult.setText(str);75         } catch (Exception e) {76             e.printStackTrace();77         }78     }79 80     private void InitLocation() {81         LocationClientOption option = new LocationClientOption();82         option.setLocationMode(LocationMode.Battery_Saving);// 设置定位模式83         option.setCoorType("bd09ll");84         option.setIsNeedAddress(true);85         mLocationClient.setLocOption(option);86     }87 }

更多相关文章

  1. 如何区别Android手机卡三大运营商
  2. 【简单的学生管理界面】Android的if语句中有字符串判断
  3. android实现json数据的解析和把数据转换成json格式的字符串
  4. Android 时间字符串 转成UTC时间转为指定时间的时间字符串
  5. android 字符串数组资源
  6. Android handler.obtainMessage()传字符串用法
  7. Android DrawText字符串的绘制
  8. Android:判断手机运营商
  9. Android xliff和字符串资源[Android开发网]

随机推荐

  1. android makefile分析及build( 转载)
  2. Android 手机运营商及网络类型判断
  3. android中进行https连接的方式
  4. android短信开发
  5. Android获取系统顶部状态栏(Status Bar)
  6. android检查权限是否获取
  7. android:点击popupwindow以外区域 popupwi
  8. android 通过 名称获取图片
  9. 【android】binder机制-servicemanager
  10. Android错误:java.lang.RuntimeException: