百度地图常常不能从BDLocation里获取地址怎回事,有时又可以
locationClient = new LocationClient(this);
// 设置定位条件
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true); // 是否打开GPS
option.setIsNeedAddress(true);
option.setCoorType("bd09ll"); // 设置返回值的坐标类型。
option.setProdName("LocationDemo"); // 设置产品线名称。强烈建议您使用自定义的产品线名称,方便我们以后为您提供更高效准确的定位服务。
option.setScanSpan(UPDATE_TIME); // 设置定时定位的时间间隔。单位毫秒
option.setAddrType("all"); //返回的定位结果
locationClient.setLocOption(option);
// 注册位置监听器
locationClient.registerLocationListener(new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation location) {
// TODO Auto-generated method stub
if (location == null) {
return;
}
if (location.getDistrict() != null) {
String addressStrs = location.getProvince() +">"+location.getCity()+">"+location.getDistrict();
if(sp2.getString("worker_city", "").equals("")){
sp2.edit().putString("worker_city", addressStrs).commit();
new Thread(new newsList()).start();// 连接服务器
}
address.setText(addressStrs);
}
}
});
locationClient.start();