zoukankan      html  css  js  c++  java
  • android百度定位

     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     @Override
    21     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 Alex
    37      * 
    38      */
    39     public class MyLocationListener implements BDLocationListener {
    40 
    41         @Override
    42         public void onReceiveLocation(BDLocation location) {
    43             // Receive Location
    44             StringBuffer sb = new StringBuffer(256);
    45             sb.append("time:");
    46             sb.append(location.getTime());
    47             sb.append("
    error code:");
    48             sb.append(location.getLocType());
    49             sb.append("
    latitude:");
    50             sb.append(location.getLatitude());
    51             sb.append("
    lontitude:");
    52             sb.append(location.getLongitude());
    53             sb.append("
    radius:");
    54             sb.append(location.getRadius());
    55             if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
    56                 sb.append("
    addr:");
    57                 sb.append(location.getAddrStr());
    58                 // 运营商信息
    59                 sb.append("
    operationers:");
    60                 sb.append(location.getOperators());
    61             }
    62             logMsg(sb.toString());
    63         }
    64     }
    65 
    66     /**
    67      * 显示请求你字符串
    68      * 
    69      * @param str
    70      */
    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 }
  • 相关阅读:
    laravel
    composer lavarel 安装
    phpstudy 500 Internal Server Error 解决办法
    阿里云php-7.2.12 安装
    mysql索引
    服务器配置-双机热备
    layui动态数据表格-分页
    layui 笔记
    Thinkphp5.1 模板路径报错
    window/linux composer安装/卸载
  • 原文地址:https://www.cnblogs.com/daishuguang/p/3878001.html
Copyright © 2011-2022 走看看