码迷,mamicode.com
首页 > 其他好文 > 详细

获取当前地址

时间:2015-06-19 18:53:32      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:获取当前地址

	/**
	 * 获取当前地址
	 */
	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);
			}

		});
	}

获取当前地址

标签:获取当前地址

原文地址:http://blog.csdn.net/wuxin782515516/article/details/46563103

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!