/**
* 获取当前地址
*/
private void getPosition() {
locationClient = new LocationClient(this);
// 设置定位条件
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true); // 是否打开GPS
option.setCoorType("bd09ll"); // 设置返回值的坐标类型。
option.setProdName("SaleBaby"); // 设置产品线名称。建议使用自定义的产品线名称,以便提供更高效准确的定位。
option.setScanSpan(UPDATE_TIME); // 设置定时定位的时间间隔。单位毫秒
locationClient.setLocOption(option);
// 注册位置监听器
locationClient.registerLocationListener(new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation location) {
// TODO Auto-generated method stub
if (location == null) {
return;
}
// 定位信息相关数据
StringBuffer sb = new StringBuffer(256);
sb.append("Time : ");
sb.append(location.getTime());
sb.append("\nError code : ");
sb.append(location.getLocType());
sb.append("\nLatitude : ");
sb.append(location.getLatitude());
sb.append("\nLontitude : ");
sb.append(location.getLongitude());
sb.append("\nRadius : ");
sb.append(location.getRadius());
if (location.getLocType() == BDLocation.TypeGpsLocation) {
sb.append("\nSpeed : ");
sb.append(location.getSpeed());
sb.append("\nSatellite : ");
sb.append(location.getSatelliteNumber());
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
sb.append("\nAddress : ");
sb.append(location.getAddrStr());
}
LOCATION_COUTNS++;
sb.append("\n检查位置更新次数:");
sb.append(String.valueOf(LOCATION_COUTNS));
LocationTools.getLocationManager(context);
String position = new LocationTools().getAddress(context);
tv_nowloc.setText(position);
}
});
}
获取当前地址
最新推荐文章于 2025-07-28 16:13:22 发布