Android解决GPS定位时LocationManager只能绑定一个LocationListener的问题
来源:互联网 发布:魅力女生知乎 编辑:程序博客网 时间:2024/06/06 04:39
之前做项目时遇到了如题的小困难, 想了一个有点解决方法, 上周在济南发现有些初学者似乎在这里有点困扰, 就发出来供大家参考下.
首先自定义一个接口
public interface CRLocationListeneri {public void onLocationChanged(Location location);}
然后些一个类, 该类需要implements LocationListener从而代替android.location.LocationListener
public class CRLocationlistener implements LocationListener {private static final String TAG = "CRLocationlistener";private static ArrayList<CRLocationListeneri> LocationListeneriList = new ArrayList<CRLocationListeneri>(2);public void onLocationChanged(Location location) {// TODO Auto-generated method stubfor (i = 0; i < LocationListeneriList.size(); i++) {LocationListeneriList.get(i).onLocationChanged(location);}}public void onProviderDisabled(String provider) {// TODO Auto-generated method stub}public synchronized static void requestUpdates(CRLocationListeneri LocationListeneri) {LocationListeneriList.add(LocationListeneri);}public synchronized static void removeUpdates(CRLocationListeneri LocationListeneri) {LocationListeneriList.remove(LocationListeneri);}public void onProviderEnabled(String provider) {// TODO Auto-generated method stub}public void onStatusChanged(String provider, int status, Bundle extras) {// TODO Auto-generated method stub}}之后就可以通过
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, mLocationListener);CRMyLocationOverlay.enableMyLocation();
将其与多个Listener绑定, 分别对Location进行不同的处理了.
- Android解决GPS定位时LocationManager只能绑定一个LocationListener的问题
- Android之GPS定位类 LocationManager、LocationListener、GpsStatus.Listener、Location详解
- Android之GPS定位类 LocationManager、LocationListener、GpsStatus.Listener、Location详解
- android GPS定位(locationmanager,高德,百度)定位的比较
- 解决“locationManager.removeUpdates()关闭不了gps定位”的方法
- android GPS LocationListener类
- android GPS LocationListener类 .
- android 基于GPS或网络定位学习(LocationManager)
- Android使用Google提供的地图实现定位时LocationListener的各个方法
- android上的GPS定位的问题
- android上的GPS定位的问题
- android locationManager定位
- android locationManager定位
- Android LocationManager 定位服务
- Android GPS技术之LocationManager
- Android 解决GPS室内定位问题(location为null)
- Android的GPS定位
- Android的gps定位
- Python入门教程
- EL表达式总结
- 软件架构学习小结
- oracle数据库之基本概念
- poj1050 二维数组最大子序列矩阵和
- Android解决GPS定位时LocationManager只能绑定一个LocationListener的问题
- 有明确的方向才有更好的未来
- Poj1088
- liferay-文件上传处理
- declare的使用 (ex20.sh)
- Django 开始支持py3
- 一道面试题
- auto_ptr解析
- 算法导论02