我使用的百度SDK版本是6.13,清单文件中已经配置了服务和key
第一次调用时候能正常获取坐标,再次调用的时候就不会执行BDLocationListener监听程序。 求大神指点。
获取坐标的代码:
public class BaiduLocationClient extends LocationClient {
@Override
public void init(Context context) {
baiduClient = new com.baidu.location.LocationClient(context);
baiduClient.registerLocationListener(new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation location) {
Log.i(TAG,"")
ExceptionHandler.saveLog2File("开始执行百度的回调方法");
if (location == null || callback == null)
return;
boolean result = false;
String resultType = StringUtils.EMPTY;
if (!result || location.getLatitude() == 4.9E-324
|| location.getLongitude() == 4.9E-324) {
Log.e(TAG, "获取坐标时出现错误!");
}
Message msg = new Message();
if (result) {
msg.obj = new LocationPoint(CoordinateEnum.GCJ02, location
.getLongitude(), location.getLatitude(), location.getRadius(),resultType);
} else {
msg.obj = new LocationPoint(CoordinateEnum.GCJ02, 0, 0,resultType);
}
callback.handleMessage(msg);
callback = null;
baiduClient.stop();
}
});
LocationClientOption option = new LocationClientOption();
option.setCoorType("gcj02");
option.setTimeOut(5000);
option.setScanSpan(5000);
option.setOpenGps(true);
baiduClient.setLocOption(option);
public void getLocation(Context context, Callback cb) {
callback = cb;
baiduClient.start();
}
/**
- 停止 */ public void stop() { baiduClient.stop(); } 这样写有什么问题吗?