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

以dialog的形式弹出定位地图

时间:2015-06-19 18:52:57      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:以dialog的形式弹出定位地图

dialog = new Dialog(context, R.style.dialog);
			// 自定义dialog宽和高
			// setDialog();

			View viewMap = LayoutInflater.from(context).inflate(
					R.layout.dialog_baidumap, null);

			iv_close = (ImageView) viewMap.findViewById(R.id.iv_close);
			mMapView = (MapView) viewMap.findViewById(R.id.mapView);

			iv_close.setOnClickListener(this);
			mBaiduMap = mMapView.getMap();

			dialog.setContentView(viewMap, new LayoutParams(650, 1000));
			dialog.show();
			initMap(); // 地图初始化

/**
	 * 地图初始化
	 */
	private void initMap() {
		mCurrentMode = LocationMode.NORMAL;
		// 开启定位图层
		mBaiduMap.setMyLocationEnabled(true);
		mMapView.showScaleControl(false);
		int count = mMapView.getChildCount();
		for (int i = 0; i < count; i++) {
			View child = mMapView.getChildAt(i);
			if (child instanceof ImageView) {
				// 隐藏百度logo
				child.setVisibility(View.INVISIBLE);
			}
			// 隐藏ZoomControl
			if (child instanceof ZoomControls) {
				child.setVisibility(View.INVISIBLE);
			}
		}
		// 定位初始化
		mLocClient = new LocationClient(this);
		mLocClient.registerLocationListener(myListener);
		LocationClientOption option = new LocationClientOption();
		option.setOpenGps(true);// 打开gps
		option.setCoorType("bd09ll"); // 设置坐标类型
		option.setScanSpan(1000);
		mLocClient.setLocOption(option);
		mLocClient.start();
	}

	/**
	 * 定位SDK监听函数
	 */
	public class MyLocationListenner implements BDLocationListener {

		@Override
		public void onReceiveLocation(BDLocation location) {
			// map view 销毁后不在处理新接收的位置
			if (location == null || mMapView == null)
				return;
			MyLocationData locData = new MyLocationData.Builder()
					.accuracy(location.getRadius())
					// 此处设置开发者获取到的方向信息,顺时针0-360
					.direction(100).latitude(location.getLatitude())
					.longitude(location.getLongitude()).build();
			mBaiduMap.setMyLocationData(locData);
			if (isFirstLoc) {
				isFirstLoc = false;
				LatLng ll = new LatLng(location.getLatitude(),
						location.getLongitude());
				MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
				mBaiduMap.animateMapStatus(u);
			}
		}

		public void onReceivePoi(BDLocation poiLocation) {
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
			// 关闭定位
		if (mMapView != null) {
			mMapView.onDestroy();
			mMapView = null;
		}
	}

以dialog的形式弹出定位地图

标签:以dialog的形式弹出定位地图

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

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