android手机百度地图开发

最近在做android手机上的地图开发,我们选用百度地图进行开发。 
 
1.百度资源下载及参考文档
http://developer.baidu.com/map/sdk-android.htm
里面的开发文档介绍的很全,并且百度还提供了demo,我们可以参考demo进行开发

下面的代码的功能是,用户可以按上下左右键选择兴趣点,选中一个兴趣点后,可以点击进去看详细信息(上下按纬度来进行排序选择,左右按经度进行排序选择)

public class SUOverlay extends ItemizedOverlay<OverlayItem> {
	static String TAG = "SUOverlay";
	public List<OverlayItem> mGeoList = new ArrayList<OverlayItem>();
	private Context mContext = null;

	Toast mToast = null;

	public SUOverlay(Drawable marker, Context context, MapView mapView) {
		super(marker, mapView);
		this.mContext = context;
	}

	public boolean onKeyDown(int keyCode, KeyEvent event, MapView mapView) {
		Log.i("ov", "clicked in overlay .");
		if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
			Log.i("ov", "KeyEvent.KEYCODE_DPAD_LEFT");
			return true;			
		}
		return false;
	}

	protected boolean onTap(int index) {
		Log.e(TAG,"on Tap");
		String convenienceItemId = null;
		if(this.getAllItem()==null){
			convenienceItemId = this.mGeoList.get(index).getSnippet();
		}else{
			convenienceItemId = this.getAllItem().get(index).getSnippet();
		}
		
		Intent intent = new Intent(mContext,
				ShopsDetailInfo.class);
		intent.putExtra("convenienceItemId",
				convenienceItemId);
		mContext.startActivity(intent);		
		//SmartUToast.showSmartUMessage(mContext, "on click", Toast.LENGTH_LONG).show();
		return true;
	}

	public boolean onTap(GeoPoint pt, MapView mapView) {
		super.onTap(pt, mapView);
		return false;
	}
	
}
public class BsnsDisActivity extends SUActivity {
	
	private static String TAG = "BsnsDisActivity";
	private static final int RESULT_BSNS_CAT = 1;
	private static final int RESULT_ERROR = -1;
	private TextView mTitle;
	private TextView mGuidTip;
	private Button mBack;
	private Button mBlank;
	static MapView mMapView;
	private SUApplication app;
	private MapController mMapController = null;
	public LocationClient mLocationClient = null;
	public BDLocationListener myLocationListener = null;
	private MyLocationOverlay myLocationOverlay = null;
	private GestureDetector gestureDetector;
	
	private int selectedItemLoc = 1;
	private int selectedItemLat = 0;
	private int level = 1;
	private static final int LEVEL_MAP = 1;//map level , can move map by key
	private static final int LEVEL_BSNS = 2;//business level , can select next marker by key
	private static final int LEVEL_BACK = 3;
	private Toast mToast = null;
	private String convenienceTypeId;
	
	private SUOverlay ov;
	private List<Point> latLoc = new ArrayList<Point>();
	// 存放overlay
	public List<OverlayItem> mGeoList = new ArrayList<OverlayItem>();
	private List<ConvenienceItemEntity> convenieceItemList;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		app = (SUApplication) this.getApplication();
		if (app.mBMapManager == null) {
			app.mBMapManager = new BMapManager(this);
			app.mBMapManager.init(SUApplication.strKey, new SUApplication.MyGeneralListener());
		}
		app.addActivity(this);
		setContentView(R.layout.ac_map_bsns);
		init();
		setListener();
		this.getBsnsDisInfo();
		pop = new PopupOverlay(BsnsDisActivity.mMapView, new PopupClickListener() {
			@Override
			public void onClickedPopup(int index) {
				
			}
		});
		ov = new SUOverlay(this.getResources().getDrawable(R.drawable.icon_mark_convenience), this, mMapView);
		mMapView.getOverlays().clear();
		pinMyLocation();
		mMapView.getOverlays().add(ov);
		mMapView.getOverlays().add(pop);
		//SUOverlay myHome = new SUOverlay(this.getResources().getDrawable(R.drawable.icon_map_house), this, mMapView);
		OverlayItem item2 = new OverlayItem(new GeoPoint(Integer.parseInt(app.nowUser.getUserLocationLatitude()),Integer.parseInt(app.nowUser.getUserLocationLongtitude())),"item2","item2");
		item2.setMarker(this.getResources().getDrawable(R.drawable.icon_map_house));
		ov.addItem(item2);
		//myHome.addItem(item2);
		//mMapView.getOverlays().add(myHome);
		
		myLocationOverlay = new MyLocationOverlay(mMapView);
		mMapView.getOverlays().add(myLocationOverlay);
		
		LocationOrientate();
		
		level = LEVEL_BSNS;
	}
	
	private void LocationOrientate() {
		mLocationClient = new LocationClient(BsnsDisActivity.this);  
		myLocationListener =new MyLocationListener();
		mLocationClient.registerLocationListener( myLocationListener );

		LocationClientOption option = new LocationClientOption();			  
	    option.setAddrType("all");   
	    option.setPoiExtraInfo(true);  		         
	    option.setProdName("通过GPS定位我当前的位置");  		         
	    option.setOpenGps(true);  		        
	    option.setPoiDistance(1500);  
	    option.disableCache(true);  		       
	    option.setCoorType("bd09ll");      
	    option.setPoiNumber(3);  
	    option.setPriority(LocationClientOption.NetWorkFirst); 
	    
	    mLocationClient.setLocOption(option);
	    mLocationClient.start();
	}
	
	public class MyLocationListener implements BDLocationListener {
		@Override
		public void onReceiveLocation(BDLocation location) {
			if (location == null){
				return;
			}
			double latitude  = location.getLatitude();
			double longitude = location.getLongitude();
						
			if(latitude==4.9E-324||longitude==4.9E-324){
				latitude = (Integer.parseInt(app.nowUser.getUserLocationLatitude()))/1e6;
				longitude = (Integer.parseInt(app.nowUser.getUserLocationLongtitude()))/1e6;
			}else{
				
			}
			
			LocationData locData = new LocationData();
			//手动将位置源置为天安门,在实际应用中,请使用百度定位SDK获取位置信息,要在SDK中显示一个位置,需要使用百度经纬度坐标(bd09ll)
			locData.latitude = latitude;
			locData.longitude = longitude;
			locData.direction = 2.0f;
			myLocationOverlay.setData(locData);
			mMapView.refresh();
		}
		public void onReceivePoi(BDLocation poiLocation) {
			
		}
	}
	
	private void init() {
		mTitle = (TextView) findViewById(R.id.map_bsns_title_text);
		mBack = (Button) findViewById(R.id.map_bsns_back_btn);
		mBlank = (Button) findViewById(R.id.map_bsns_blank_btn);
		mMapView = (MapView) findViewById(R.id.map_bsns_mapview);

		mMapController = mMapView.getController();
		mMapView.getController().setZoom(15);
		mMapView.getController().enableClick(false);
		mMapView.setBuiltInZoomControls(false);
		mGuidTip = (TextView) findViewById(R.id.map_dis_guid_tip);
		
		String convenienceTypeName = getIntent().getExtras().getString("ConvenienceTypeName");
		mTitle.setText((CharSequence) convenienceTypeName==null?"":convenienceTypeName);
		convenienceTypeId = getIntent().getExtras().getString("ConvenienceTypeId");
	}

	/**
	 * 设置监听
	 */
	private void setListener() {
		mBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				BsnsDisActivity.this.finish();
				app.removeActivity(BsnsDisActivity.this);
			}
		});
		mBlank.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ConvenienceItemEntity itemEntity = convenieceItemList.get(selectedItemLoc-1);
				Intent intent = new Intent(BsnsDisActivity.this,
						ShopsDetailInfo.class);
				intent.putExtra("convenienceItemId",
						itemEntity.getConvenienceItemId());
				startActivity(intent);				
			}
		});
	}

	/**
	 * 添加marker
	 * @param item
	 */
	private void addMarker(OverlayItem item) {
		ov.addItem(item);
		mMapView.refresh();
	}

	/**
	 * 批量添加marker
	 * @param items
	 */
	private void addMarker(List<OverlayItem> items) {
		ov.addItem(items);
		mMapView.refresh();
		mMapView.getController().animateTo(new GeoPoint(Integer.parseInt(app.nowUser.getUserLocationLatitude()),
				Integer.parseInt(app.nowUser.getUserLocationLongtitude())));
	}
	/**
	 * 
	 */
	private void pinMyLocation(){
		
		
		
		
		GraphicsOverlay graphicsOverlay50 = new GraphicsOverlay(mMapView);
        mMapView.getOverlays().add(graphicsOverlay50);
//        GraphicsOverlay graphicsOverlay100 = new GraphicsOverlay(mMapView);
//        mMapView.getOverlays().add(graphicsOverlay100);
//        GraphicsOverlay graphicsOverlay150 = new GraphicsOverlay(mMapView);
//        mMapView.getOverlays().add(graphicsOverlay150);
        

		Geometry geometry50 = new Geometry();
		geometry50.setCircle(new GeoPoint(Integer.parseInt(app.nowUser.getUserLocationLatitude()), Integer.parseInt(app.nowUser.getUserLocationLongtitude())), 500);

		Symbol lineSymbol50 = new Symbol();
  		Symbol.Color geoColor50 = lineSymbol50.new Color();
  		geoColor50.red = 19;
  		geoColor50.green = 19;
  		geoColor50.blue = 70;
  		geoColor50.alpha =150;
  		lineSymbol50.setLineSymbol(geoColor50, 4);
  		
  		
  		Graphic lineGraphic50 = new Graphic(geometry50, lineSymbol50);
  		
  		Geometry geometry100 = new Geometry();
		geometry100.setCircle(new GeoPoint(Integer.parseInt(app.nowUser.getUserLocationLatitude()), Integer.parseInt(app.nowUser.getUserLocationLongtitude())), 1000);
		Symbol lineSymbol100 = new Symbol();
  		Symbol.Color geoColor100 = lineSymbol100.new Color();
  		geoColor100.red = 124;//133;
  		geoColor100.green = 252;//224;
  		geoColor100.blue = 0;
  		geoColor100.alpha = 150;
  		lineSymbol100.setLineSymbol(geoColor100, 4);
  		Graphic lineGraphic100 = new Graphic(geometry100, lineSymbol100);
  		
  		Geometry geometry150 = new Geometry();
		geometry150.setCircle(new GeoPoint(Integer.parseInt(app.nowUser.getUserLocationLatitude()), Integer.parseInt(app.nowUser.getUserLocationLongtitude())), 1500);
		Symbol lineSymbol150 = new Symbol();
  		Symbol.Color geoColor150 = lineSymbol150.new Color();
  		geoColor150.red = 0;
  		geoColor150.green = 255;
  		geoColor150.blue =255;
  		geoColor150.alpha = 150;
  		lineSymbol150.setLineSymbol(geoColor150, 4);
  		Graphic lineGraphic150 = new Graphic(geometry150, lineSymbol150);
  		
  		
  		
//  		graphicsOverlay150.setData(lineGraphic150);
//  		graphicsOverlay100.setData(lineGraphic100);
  		graphicsOverlay50.setData(lineGraphic50);
  		graphicsOverlay50.setData(lineGraphic150);
  		graphicsOverlay50.setData(lineGraphic100);
//		mMapView.refresh();
//		mMapView.getController().animateTo(new GeoPoint(app.nowUser.getLatitude(),
//		app.nowUser.getLongitude()));
  		
  		
	}
	/**
	 * 按纬度选择 下键控制
	 * 调到下一marker,并进行标记,初始标记第一个
	 */
	private void toNextMarkerLat(){
		
		if(ov.size()>mGeoList.size()+1 ){
			ov.removeItem(ov.getItem(ov.size()-1));
		}
		
		selectedItemLat = selectedItemLat+1;
		selectedItemLat = selectedItemLat > ov.size()-1?1:selectedItemLat;
		
		OverlayItem item = new OverlayItem(ov.getItem(latLoc.get(selectedItemLat-1).x).getPoint(),"","");		
		item.setMarker(getResources().getDrawable(R.drawable.icon_runner));
		ov.addItem(item);
		
		pinItemMarkPop(ov.getItem(latLoc.get(selectedItemLat-1).x));
		mMapView.refresh();
		
		Log.i(TAG, selectedItemLat+"--latnextmove("+ov.getItem(latLoc.get(selectedItemLat-1).x).getPoint().getLatitudeE6()+")");
		selectedItemLoc = latLoc.get(selectedItemLat-1).x;
	}
	
	/**
	 * 按纬度选择 上键控制
	 * 调到上一marker,并进行标记,初始标记最后一个
	 */
	private void toPreviousMarkerLat(){
		if(ov.size()>(mGeoList.size()+1) ){
			ov.removeItem(ov.getItem(ov.size()-1));
		}
		selectedItemLat = selectedItemLat-1;
		if(selectedItemLat< 1){
			selectedItemLat = ov.size()-1;
		}
		
		OverlayItem item = new OverlayItem(ov.getItem(latLoc.get(selectedItemLat-1).x).getPoint(),"","");
		item.setMarker(getResources().getDrawable(R.drawable.icon_runner));
		ov.addItem(item);
		pinItemMarkPop(ov.getItem(latLoc.get(selectedItemLat-1).x));
		mMapView.refresh();
		
		Log.i(TAG, selectedItemLat+"--latpremove("+ov.getItem(latLoc.get(selectedItemLat-1).x).getPoint().getLatitudeE6()+")");
		selectedItemLoc = latLoc.get(selectedItemLat-1).x;
	}
	
	/**
	 * 按经度选择,右键控制
	 * 调到下一marker,并进行标记,初始标记第一个
	 */
	private void toNextMarkerLoc(){
		if(ov.size()>(mGeoList.size()+1) ){
			ov.removeItem(ov.getItem(ov.size()-1));
		}
		selectedItemLoc = selectedItemLoc+1;
		selectedItemLoc = selectedItemLoc > ov.size()-1?1:selectedItemLoc;
		
		OverlayItem item = new OverlayItem(ov.getItem(selectedItemLoc).getPoint(),"","");
		item.setMarker(getResources().getDrawable(R.drawable.icon_runner));
		ov.addItem(item);
		
		mMapView.refresh();
		
		pinItemMarkPop(ov.getItem(selectedItemLoc));
		
		Log.i(TAG, selectedItemLoc+"---lonnextmove("+ov.getItem(selectedItemLoc).getPoint().getLongitudeE6()+")");
		Point p = new Point(selectedItemLoc,ov.getItem(selectedItemLoc).getPoint().getLatitudeE6());
		selectedItemLat = latLoc.indexOf(p);
		Log.i(TAG, "lon lat:"+selectedItemLat);
	}
	
	/**
	 * 调到上一marker,并进行标记,初始标记最后一个
	 */
	private void toPreviousMarkerLoc(){
		if(ov.size()>(mGeoList.size()+1) ){
			ov.removeItem(ov.getItem(ov.size()-1));
		}
		selectedItemLoc = selectedItemLoc-1;
		if(selectedItemLoc < 1){
			selectedItemLoc = ov.size()-1;
		}
		OverlayItem item = new OverlayItem(ov.getItem(selectedItemLoc).getPoint(),"","");
		item.setMarker(getResources().getDrawable(R.drawable.icon_runner));
		ov.addItem(item);
		
		pinItemMarkPop(ov.getItem(selectedItemLoc));
		mMapView.refresh();
		Log.i(TAG, selectedItemLoc+"--lonpremove("+ov.getItem(selectedItemLoc).getPoint().getLongitudeE6()+")");
		
		Point p = new Point(selectedItemLoc,ov.getItem(selectedItemLoc).getPoint().getLatitudeE6());
		selectedItemLat = latLoc.indexOf(p);
		Log.i(TAG, "lon lat:"+selectedItemLat);
	}
	
	/**
	 * 删除特殊标记的marker
	 */
	private void deleteSelectedMarker(){
		if(ov.size() > mGeoList.size()){
			ov.removeItem(ov.getItem(ov.size()-1));
			mMapView.refresh();
		}
	}
	
	private void focusToBack(){
		mBack.setFocusable(true);
		mBack.setFocusableInTouchMode(true);
		mBack.requestFocus();
	}
	
	private void focusToBlank(){
		mBlank.setFocusable(true);
		mBlank.setFocusableInTouchMode(true);
		mBlank.requestFocus();
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		Log.e(TAG,"onActivityResult level="+level);
		level = LEVEL_BSNS;
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		Log.e(TAG,"onKeyDown:level="+level);
		Log.e(TAG,"keyCode==left"+(keyCode == KeyEvent.KEYCODE_DPAD_LEFT));
		Log.e(TAG,"keyCode==right"+(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT));
		
		if (keyCode == KeyEvent.KEYCODE_VOLUME_UP||keyCode==KeyEvent.KEYCODE_F5) {
			mMapController.zoomIn();
			return true;
		} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN||keyCode==KeyEvent.KEYCODE_F4) {
			mMapController.zoomOut();
			return true;
		} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER&&level==LEVEL_BSNS) {
			
			return true;
		} else if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER&& level == LEVEL_MAP){
			level = LEVEL_BSNS;
			focusToBlank();
			if(ov.size()<mGeoList.size() ){
				OverlayItem item = new OverlayItem(ov.getItem(latLoc.get(selectedItemLat).x).getPoint(),"","");		
				item.setMarker(getResources().getDrawable(R.drawable.icon_runner));
				ov.addItem(item);
				mMapView.refresh();
				pinItemMarkPop(item);
			}
			mGuidTip.setText( R.string.map_guid_movepoint);
			//SmartUToast.showSmartUMessage(BsnsDisActivity.this, "您现在可以选择商户",Toast.LENGTH_LONG).show();
			return true;
		} else if(keyCode == KeyEvent.KEYCODE_ENTER&& level == LEVEL_MAP){
			level = LEVEL_BSNS;
			focusToBlank();
			if(ov.size()<mGeoList.size() ){
				OverlayItem item = new OverlayItem(ov.getItem(latLoc.get(selectedItemLat).x).getPoint(),"","");		
				item.setMarker(getResources().getDrawable(R.drawable.icon_runner));
				ov.addItem(item);
				mMapView.refresh();
				pinItemMarkPop(item);
				
			}
			mGuidTip.setText( R.string.map_guid_movepoint);
			//SmartUToast.showSmartUMessage(BsnsDisActivity.this, "您现在可以选择商户",Toast.LENGTH_LONG).show();
			return true;
		} else if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT && level == LEVEL_BSNS){
			if(mBack.isFocused()){
				focusToBlank();
				mGuidTip.setText( R.string.map_guid_movepoint);
				
			}
			toPreviousMarkerLoc();
			return true;
		} else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && level == LEVEL_MAP){
			mGuidTip.setText( R.string.map_guid_movemap);
			
		} else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && level == LEVEL_BSNS){
			if(mBack.isFocused()){
				focusToBlank();
				mGuidTip.setText( R.string.map_guid_movepoint);
			}
			toNextMarkerLoc();
			return true;
		} else if(keyCode == KeyEvent.KEYCODE_DPAD_UP && level == LEVEL_BSNS){
			if(mBack.isFocused()){
				focusToBlank();
				mGuidTip.setText(R.string.map_guid_movepoint);
			}
			toNextMarkerLat();
			return true;
		} else if(keyCode == KeyEvent.KEYCODE_DPAD_DOWN && level == LEVEL_BSNS){
			if(mBack.isFocused()){
				focusToBlank();
				mGuidTip.setText( R.string.map_guid_movepoint);
			}
			toPreviousMarkerLat();
			return true;
		}  else if(keyCode == KeyEvent.KEYCODE_BACK && level == LEVEL_MAP){
			if(mBack.isFocused()){
				return super.onKeyDown(keyCode, event);
				
			}
			focusToBack();
			if(ov.size()>mGeoList.size()+1 ){
				ov.removeItem(ov.getItem(ov.size()-1));
				mMapView.refresh();
				pop.hidePop();
			}
			mGuidTip.setText( "当前焦点在返回按钮上");
			//SmartUToast.showSmartUMessage(BsnsDisActivity.this, "当前焦点在【返回】按钮上",Toast.LENGTH_LONG).show();
			return true;
		}	else if(keyCode == KeyEvent.KEYCODE_BACK && level == LEVEL_BSNS){
			level = LEVEL_MAP;
			mMapView.setFocusable(true);
			mMapView.setFocusableInTouchMode(true);
			mMapView.requestFocus();
			mGuidTip.setText( R.string.map_guid_movemap);
			//SmartUToast.showSmartUMessage(BsnsDisActivity.this, "您现在可以移动地图了",Toast.LENGTH_LONG).show();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
	
	 @Override
	    protected void onPause() {
	        mMapView.onPause();
	       // mMapView.removeViewsInLayout(0, 4);
	        super.onPause();
	    }
	    
	    @Override
	    protected void onResume() {
	        super.onResume();
	        mMapView.onResume();
	        mMapView.refresh();
	        //pinMyLocation();
	    }
	    
	    @Override
	    protected void onSaveInstanceState(Bundle outState) {
	    	super.onSaveInstanceState(outState);
	    	mMapView.onSaveInstanceState(outState);
	    	ov.mGeoList=ov.getAllItem();
	    	
	    }
	    
	    @Override
	    protected void onRestoreInstanceState(Bundle savedInstanceState) {
	    	super.onRestoreInstanceState(savedInstanceState);
	    	mMapView.onRestoreInstanceState(savedInstanceState);
	    	ov.mGeoList=ov.getAllItem();
	    }
	    
	    @Override
	    protected void onDestroy() {
	        mMapView.destroy();
	        super.onDestroy();
	    }
	    
	    private void getBsnsDisInfo(){
			new Thread(){
				public void run() {
					try{
						List<OrderByEntity> orderByEntity = new ArrayList();
						OrderByEntity order = new OrderByEntity();
						order.setOrderCol("item_longitude");
						order.setOrderType("asc");
						orderByEntity.add(order);

	
						ConvenienceItemAckEntity ack = SUService.getInstance().getBsns(app.nowUser, "COMMON",convenienceTypeId, null, orderByEntity, null, null);
						Log.i(TAG, ack.getAckCode().toString());
						Log.i(TAG, ack.getAckMsg().toString());
						Message msg = new Message();
						if(ack.getAckCode().toString().indexOf("INFO") != -1){
							msg.what = RESULT_BSNS_CAT;
						} else {
							msg.what = RESULT_ERROR;
						}
						msg.obj = ack;
						myHandler.sendMessage(msg);
					}catch(Exception e){
						
					}
					
				};
			}.start();
		}
	    
	    Handler myHandler = new Handler(){
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case RESULT_BSNS_CAT:
					ConvenienceItemAckEntity ack = (ConvenienceItemAckEntity)msg.obj;
					pinItemMark(ack.getResults());
					break;

				default:
					break;
				}
			};
		};
		
		private void pinItemMark(List<ConvenienceItemEntity> itemList){
			convenieceItemList = new ArrayList<ConvenienceItemEntity>();
			for(int i=0;i<itemList.size();i++){
				ConvenienceItemEntity itemEntity = itemList.get(i);
				int lat = Integer.parseInt(itemEntity.getItemLatitude());
				int loc = Integer.parseInt(itemEntity.getItemLongtude());
				OverlayItem item = new OverlayItem(new GeoPoint(lat, loc),itemEntity.getConvenienceItemName() , itemEntity.getConvenienceItemId());
				
				View drawableView = LayoutInflater.from(BsnsDisActivity.this).inflate(
						R.layout.map_drawable_pin, null);// 获取要转换的View资源
				TextView TestText = (TextView)drawableView.findViewById(R.id.map_drawable_text);
				TestText.setText(item.getTitle());//将每个点的Title在弹窗中以文本形式显示出来		
				
				Bitmap drawableBitmap = convertViewToBitmap(drawableView);
				
				Drawable draw = new BitmapDrawable(drawableBitmap);
		
				item.setMarker(draw);
				
				convenieceItemList.add(itemEntity);
				mGeoList.add(item);
				Point locPoint = new Point();
				locPoint.x = i+1;
				locPoint.y = lat;
				latLoc.add(locPoint);				
			}
			
			addMarker(mGeoList);
			for (int i = 0; i < latLoc.size(); i++){  
	                for (int j = 1; j < latLoc.size() - i; j++) { 
	            	  Point p1 = latLoc.get((j-1));
	            	  Point p2 = latLoc.get(j);
	            	  
	            	  if(p1.y>p2.y){
	            		  Point temp = p1;
	            		  latLoc.set(j-1, p2);
	            		  latLoc.set(j, p1);
	            	  }
	            	  if(latLoc.get(j-1).x==0){
	            		  selectedItemLat = j-1;
	            	  }
	              }
			}
			for(int i=0;i<latLoc.size();i++){
				Log.i(TAG, "("+latLoc.get(i).x+","+mGeoList.get(i).getPoint().getLongitudeE6()+","+latLoc.get(i).y+")");
			}
//			for (int i = 0; i < mGeoList.size(); i++) {
//				addMarker(mGeoList.get(i));
//			}
		}
		
		static PopupOverlay pop = null;
		private void pinItemMarkPop(OverlayItem item){
			if (pop != null) {
				pop.hidePop();
			}
			
			//Bitmap[] bmps = new Bitmap[2];
			View popview = LayoutInflater.from(BsnsDisActivity.this).inflate(
					R.layout.map_popup_view, null);// 获取要转换的View资源
			TextView TestText = (TextView)popview.findViewById(R.id.map_popup_text);
			TestText.setText(item.getTitle());//将每个点的Title在弹窗中以文本形式显示出来		
			
			Bitmap popbitmap = convertViewToBitmap(popview);
	        
		    pop.showPopup(popbitmap, item.getPoint(), 32);
		}
		
		public static Bitmap convertViewToBitmap(View view) {
			view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
					MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
			view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
			view.buildDrawingCache();
			Bitmap bitmap = view.getDrawingCache();

			return bitmap;
		}
		
		
}



你可能感兴趣的:(android,百度地图)