1.BMapManager 初始化在setViewContent之前 否则会报错
2.在application标签中声明service组件,每个app拥有自己单独的定位service
<service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote" > </service>
3.初始化LocationClient类时需要注意:LocationClient类必须在主线程中声明。需要Context类型的参数。
Context需要时全进程有效的context,推荐用getApplicationConext获取全进程有效的context
public LocationClient mLocationClient = null; public BDLocationListener myListener = new MyLocationListener(); public void onCreate() { mLocationClient = new LocationClient(getApplicationContext()); //声明LocationClient类 mLocationClient.registerLocationListener( myListener ); //注册监听函数 }
4.BDLocationListener接口有2个方法需要实现: 1.接收异步返回的定位结果,参数是BDLocation类型参数。 2.接收异步返回的POI查询结果,参数是BDLocation类型参数。
5.发起定位:public int requestLocation()
发起定位,异步获取当前位置。因为是异步的,所以立即返回,不会引起阻塞。定位结果在ReceiveListener的方法OnReceive方法的参数中返回。
需要注意:当定位SDK从定位依据判定,位置和上一次没发生变化,而且上一次定位结果可用时,则不会发起网络请求,而是返回上一次的定位结果。 返回值:
- 0:正常发起了定位。
- 1:服务没有启动。
- 2:没有监听函数。
- 6:请求间隔过短。 前后两次请求定位时间间隔不能小于1000ms。