百度地图自定义多点规划路线

所谓自定义多点规划路线,就是从服务器下载多点的坐标,标注在百度地图上,在按照一定顺序连接规划路线。

(由于本人也是实习小白,所以有做错的,费事麻烦的欢迎大神指出,让我少走点弯路^^)

好戏开始~~(先局部,再整体)

首先数据库文件就省略了,第一是我还没研究明白,第二太多(如果有需要可以找我)

1.这个是spinner,用来选择URL,然后返回到数据库,数据库下载该URL的站点信息。(获取lineName,switch相应的“部分url”,用静态方法返回拼接数据库中URL

		zdlist.add("浦电线");
		zdlist.add("华苑线");
		zdlist.add("海泰线");
		// zdlist.add("福州");
		// zdlist.add("厦门");
		lineAdapter = new ArrayAdapter(this,
				android.R.layout.simple_spinner_item, zdlist);
		lineAdapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		lineSpinner = (Spinner) findViewById(R.id.spinner1);
		lineSpinner.setAdapter(lineAdapter);
		lineSpinner
				.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
					public void onItemSelected(AdapterView arg0, View arg1,
							int arg2, long arg3) {
						String lineName = lineSpinner.getSelectedItem()
								.toString();
						SelectURL.SURL(lineName);
						System.out.println("您选择的是:" + lineAdapter.getItem(arg2));
						arg0.setVisibility(View.VISIBLE);
					}

					public void onNothingSelected(AdapterView arg0) {
						System.out.println("NONE");
						arg0.setVisibility(View.VISIBLE);
					}
				});
		/* 下拉菜单弹出的内容选项触屏事件处理 */
		lineSpinner.setOnTouchListener(new Spinner.OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub

				return false;
			}
		});
		/* 下拉菜单弹出的内容选项焦点改变事件处理 */
		lineSpinner
				.setOnFocusChangeListener(new Spinner.OnFocusChangeListener() {
					public void onFocusChange(View v, boolean hasFocus) {
						// TODO Auto-generated method stub

					}
				});
2.这个是标注点点击事件跟地图点击事件。这个泡泡就是这样显示,点击地图消失。(注意:当你调用BaiduMap.OnMapClickListener这个接口时,点击地图时hideInfoWindow出于某种原因可能不起作用,这也是我想向各位大神请教的。我的方法用bdMap重写这个方法,是可以的。)我做安卓没多长时间,对泛型接触的不是很多,在我的List里有站点名称站点经度纬度等等,请问各位大神,我用点击Marker返回的经纬度可不可以匹配到list里相应的站点,从而获取其站点名称?

// 地图标注点击处理
		bdMap.setOnMarkerClickListener(new OnMarkerClickListener() {

			@Override
			public boolean onMarkerClick(Marker mMaker) {
				// TODO Auto-generated method stub
				// 泡泡
				 List zdu = new ArrayList();
				 LatLng a = mMaker.getPosition();
				 String b = "车站";
				 popupText = new TextView(BusLineSelectActivity.this);
				 popupText.setBackgroundResource(R.drawable.popup);
				 popupText.setTextColor(0xFF000000);
				 popupText.setText(b);
				 popupText.setGravity(Gravity.CENTER);
				 bdMap.showInfoWindow(new InfoWindow(popupText, a, 0));
				return false;
			}
		});
		bdMap.setOnMapClickListener(new OnMapClickListener() {

			@Override
			public boolean onMapPoiClick(MapPoi arg0) {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public void onMapClick(LatLng arg0) {
				// TODO Auto-generated method stub
				bdMap.hideInfoWindow();
			}
		});
	}

3.这个是获取数据库中点的坐标画在地图上,站点嘛,

问题:如果不删除数据库文件,情况1在更换路线时还保留之前的站点,clear地图时还会在画出来,情况2显示不是唯一primary key,求解!!

@SuppressLint("HandlerLeak")
	private void zhanDianXianShi() {
		// TODO Auto-generated method stub
		new Thread(new Runnable() {

			@Override
			public void run() {
				// 删除本地数据库信息
				bmydb.deleteZhanDianUtil();
				bmydb.deleteZhanDianLocalUtil();
				bmydb.downloadZhanDian();
				drivingSearch(drivintResultIndex);
				Message msgDown = new Message();
				Bundle b = new Bundle();// 存放数据
				b.putInt("result", 2);
				msgDown.setData(b);
				handler.sendMessage(msgDown); // 发送消息
				Log.i("更新车辆数据:", "ok");
			}
		}).start(); // 开启线程

		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				Bundle data = msg.getData();
				int iReturnVal = data.getInt("result");

				Log.i("bus update", "车辆同步结果为-->" + String.valueOf(iReturnVal));
				// UI界面的更新等相关操作
				if (2 == iReturnVal) {
					String msgFinish = "站点查询完成";
					Toast.makeText(getApplicationContext(), msgFinish,
							Toast.LENGTH_SHORT).show();
					List listBuss = null;
					listBuss = bmydb.searchBusList();
					for (int i = 0; i < listBuss.size() / 2; i++) {
						double Latitude = listBuss.get(i).getLat();
						double Longitude = listBuss.get(i).getLng();
						int busid = listBuss.get(i).getZhanDianid();
						BitmapDescriptor bitmap;

						// 构建图标
						bitmap = BitmapDescriptorFactory
								.fromResource(R.drawable.icon_gcoding);

						if (busid == 0) {
							// 构建Marker
							bitmap = BitmapDescriptorFactory
									.fromResource(R.drawable.icon_gcoding);

						}

						LatLng ll = new LatLng(Latitude, Longitude);
						// 构建MarkerOption,用于在地图上添加Marker
						OverlayOptions option = new MarkerOptions()
								.position(ll).icon(bitmap).zIndex(9) // 设置marker所在层级
								.draggable(true); // 设置手势拖拽;
						// 在地图上添加Marker,并显示
						mMakerBus = (Marker) (bdMap.addOverlay(option));

						String strMaker = "maker-zhandian" + String.valueOf(i);

						Bundle bundle = new Bundle();
						bundle.putSerializable("ZhandianUtil", listBuss.get(i));

						mMakerBus.setExtraInfo(bundle);
						Log.d(strMaker, ll.toString());
						makerBus.add(mMakerBus);
						System.out.println("画站点啊啊啊啊啊啊");
						MapStatusUpdate u = MapStatusUpdateFactory
								.newLatLng(ll);
						bdMap.animateMapStatus(u);

						// ll = null;
					}

					isMark = true;
				} else {
					String msgFinish = "站点查询失败";
					Toast.makeText(getApplicationContext(), msgFinish,
							Toast.LENGTH_SHORT).show();
				}
			}
		};

	}
4.重点来了,这个就是连点成线的关键代码,其实就一句话
drivingOption.passBy(lu);

但是我要提几个我认为我代码里的重点。

1)泛型,当你需要将一个泛型中的某一个值,比如说是经度,这时候用到的get和set点对点的赋值。例d1.setLng(d2.getLng)。当你需要像代码中一样,不是点对点,要将精度跟纬度合成这个LatLng ll,这时候应用add这个方法。

2)drivingOption.passBy(lu);lu是List的对象而且必须是List对象,list里就是经过的点。除此之外,必须要起点和终点。OK

/**
	 * 驾车线路查询
	 */
	private void drivingSearch(int index) {
		List zdu = new ArrayList();
		List lu = new ArrayList();
		zdu = bmydb.searchBusList();
		int endn = zdu.size() / 2 - 1;
		System.out.println(endn);
		double lat = zdu.get(0).getLat();
		double lng = zdu.get(0).getLng();
		LatLng stall = new LatLng(lat, lng);
		LatLng endll = new LatLng(zdu.get(endn).getLat(), zdu.get(endn)
				.getLng());
		for (int i = 0; i < zdu.size() / 2; i++) {
			double Latitude = zdu.get(i).getLat();
			double Longitude = zdu.get(i).getLng();
			LatLng ll = new LatLng(Latitude, Longitude);
			PlanNode node = PlanNode.withLocation(ll);
			lu.add(node);
		}
		DrivingRoutePlanOption drivingOption = new DrivingRoutePlanOption();
		drivingOption.from(PlanNode.withLocation(stall));
		drivingOption.to(PlanNode.withLocation(endll));
		drivingOption.passBy(lu);
		routePlanSearch.drivingSearch(drivingOption);// 发起驾车路线规划
	}
下面就贴上这个activity的源码,如还有不懂的可以和我交流

package com.zwin.activity;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMap.OnMapClickListener;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.InfoWindow;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.Overlay;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.BaiduMap.OnMarkerClickListener;
import com.baidu.mapapi.map.InfoWindow.OnInfoWindowClickListener;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.overlayutil.BusLineOverlay;
import com.baidu.mapapi.overlayutil.DrivingRouteOverlay;
import com.baidu.mapapi.search.busline.BusLineResult;
import com.baidu.mapapi.search.busline.BusLineSearch;
import com.baidu.mapapi.search.busline.BusLineSearchOption;
import com.baidu.mapapi.search.busline.OnGetBusLineSearchResultListener;
import com.baidu.mapapi.search.core.PoiInfo;
import com.baidu.mapapi.search.core.RouteLine;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;
import com.baidu.mapapi.search.poi.PoiCitySearchOption;
import com.baidu.mapapi.search.poi.PoiDetailResult;
import com.baidu.mapapi.search.poi.PoiResult;
import com.baidu.mapapi.search.poi.PoiSearch;
import com.baidu.mapapi.search.route.DrivingRouteLine;
import com.baidu.mapapi.search.route.DrivingRoutePlanOption;
import com.baidu.mapapi.search.route.DrivingRouteResult;
import com.baidu.mapapi.search.route.OnGetRoutePlanResultListener;
import com.baidu.mapapi.search.route.PlanNode;
import com.baidu.mapapi.search.route.RoutePlanSearch;
import com.baidu.mapapi.search.route.TransitRouteResult;
import com.baidu.mapapi.search.route.WalkingRouteResult;
import com.baidu.mapapi.search.route.DrivingRoutePlanOption.DrivingPolicy;
import com.zwin.entity.ZhanDianUtil;
import com.zwin.tool.DBManagerXianLu;
import com.zwin.tool.DatabaseHelper;
import com.zwin.tool.FileServiceUtil;
import com.zwin.tool.LatlonUtil;
import com.zwin.tool.SelectURL;
import com.zwin.tool.ServerURL;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 公交线路查询 BusLineSearchActivity
 * 
 * @author
 *
 */
public class BusLineSelectActivity extends Activity implements OnClickListener {
	// public class CopyOfBusLineSearchActivity extends Activity {
	// 百度地图定位相关
	LocationClient mLocClient;
	public MyLocationListenner myListener = new MyLocationListenner();
	BitmapDescriptor mCurrentMarker;

	DatabaseHelper mydbhelper = new DatabaseHelper(BusLineSelectActivity.this);
	DBManagerXianLu bmydb = new DBManagerXianLu(mydbhelper);
	private List makerBus = new ArrayList();

	private Handler handler; // 声明一个Handler对象
	private EditText cityEt;
	private EditText buslineEt;
	private Button searchBtn;
	ImageView huigui;
	ImageView zhandian;

	int nodeIndex = -1;// 节点索引,供浏览节点时使用
	RouteLine route = null;
	private MapView mapView;
	private BaiduMap bdMap;
	private Marker mMakerBus;
	private TextView popupText = null;// 泡泡view
	private RoutePlanSearch routePlanSearch;// 路径规划搜索接口
	private int totalLine = 0;// 记录某种搜索出的方案数量
	private int drivintResultIndex = 0;// 驾车路线方案index
	private int index = -1;

	boolean isMark = false;
	boolean isFirstLoc = true;// 是否首次定位
	boolean isLocation = true;

	private String city;// 城市
	private String busline;// 公交路线
	private List buslineIdList;// 存储公交线路的uid
	private int buslineIndex = 0;// 标记第几个路线

	private PoiSearch poiSearch;
	private BusLineSearch busLineSearch;

	// 选择URL
	private Spinner lineSpinner; // 线路
	ArrayAdapter lineAdapter; // 线路适配器
	private List zdlist = new ArrayList();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.xianluchaxun);
		init();
		setonclicklisten();
		// 第一步:添加一个下拉列表项的list,这里添加的项就是下拉列表的菜单项
		zdlist.add("浦电线");
		zdlist.add("华苑线");
		zdlist.add("海泰线");
		// zdlist.add("福州");
		// zdlist.add("厦门");
		lineAdapter = new ArrayAdapter(this,
				android.R.layout.simple_spinner_item, zdlist);
		lineAdapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		lineSpinner = (Spinner) findViewById(R.id.spinner1);
		lineSpinner.setAdapter(lineAdapter);
		lineSpinner
				.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
					public void onItemSelected(AdapterView arg0, View arg1,
							int arg2, long arg3) {
						String lineName = lineSpinner.getSelectedItem()
								.toString();
						SelectURL.SURL(lineName);
						System.out.println("您选择的是:" + lineAdapter.getItem(arg2));
						arg0.setVisibility(View.VISIBLE);
					}

					public void onNothingSelected(AdapterView arg0) {
						System.out.println("NONE");
						arg0.setVisibility(View.VISIBLE);
					}
				});
		/* 下拉菜单弹出的内容选项触屏事件处理 */
		lineSpinner.setOnTouchListener(new Spinner.OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub

				return false;
			}
		});
		/* 下拉菜单弹出的内容选项焦点改变事件处理 */
		lineSpinner
				.setOnFocusChangeListener(new Spinner.OnFocusChangeListener() {
					public void onFocusChange(View v, boolean hasFocus) {
						// TODO Auto-generated method stub

					}
				});

		// 不显示百度地图Logo
		mapView.removeViewAt(1);
		mapView.showZoomControls(true);
	}

	/**
	 * 初始化操作
	 */
	private void init() {
		mapView = (MapView) findViewById(R.id.mapview);
		bdMap = mapView.getMap();
		// 开启定位图层
		bdMap.setMyLocationEnabled(true);
		bdMap.setMapStatus(MapStatusUpdateFactory.zoomTo(15.0f));
		huigui = (ImageView) findViewById(R.id.huiguidingwei);
		zhandian = (ImageView) findViewById(R.id.zhandianchaxun);
		searchBtn = (Button) findViewById(R.id.button1);
		buslineIdList = new ArrayList();
		poiSearch = PoiSearch.newInstance();
		busLineSearch = BusLineSearch.newInstance();
		// 定位相关
		mCurrentMarker = BitmapDescriptorFactory.fromResource(R.drawable.pin);
		bdMap.setMyLocationConfigeration(new MyLocationConfiguration(null,
				false, null));
		// 定位初始化
		mLocClient = new LocationClient(BusLineSelectActivity.this);
		mLocClient.registerLocationListener(myListener);
		LocationClientOption option = new LocationClientOption();
		option.setIsNeedAddress(true);
		option.setOpenGps(true);// 打开gps
		option.setCoorType("bd09ll"); // 设置坐标类型,百度返回的坐标类型
		option.setScanSpan(1000);// 扫描1公里
		mLocClient.setLocOption(option);
		mLocClient.start();
		routePlanSearch = RoutePlanSearch.newInstance();
		routePlanSearch
				.setOnGetRoutePlanResultListener(routePlanResultListener);
	}

	private void setonclicklisten() {
		// TODO Auto-generated method stub
		huigui.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				isFirstLoc = true;
				Toast.makeText(BusLineSelectActivity.this, "回归定位",
						Toast.LENGTH_SHORT).show();
			}
		});
		zhandian.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (isMark) {
					isMark = false;
					bdMap.clear();
					System.out.println("移除标记");
				}
				isFirstLoc = true;
				Toast.makeText(BusLineSelectActivity.this, "还原",
						Toast.LENGTH_SHORT).show();
			}
		});
		searchBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (isMark) {
					isMark = false;
					bdMap.clear();
					System.out.println("移除标记");
				}
				String msgFinish = "站点查询中...";
				Toast.makeText(getApplicationContext(), msgFinish,
						Toast.LENGTH_SHORT).show();

				zhanDianXianShi();
			}
		});
		// 地图标注点击处理
		bdMap.setOnMarkerClickListener(new OnMarkerClickListener() {

			@Override
			public boolean onMarkerClick(Marker mMaker) {
				// TODO Auto-generated method stub
				// 泡泡
				 List zdu = new ArrayList();
				 LatLng a = mMaker.getPosition();
				 String b = "车站";
				 popupText = new TextView(BusLineSelectActivity.this);
				 popupText.setBackgroundResource(R.drawable.popup);
				 popupText.setTextColor(0xFF000000);
				 popupText.setText(b);
				 popupText.setGravity(Gravity.CENTER);
				 bdMap.showInfoWindow(new InfoWindow(popupText, a, 0));
				return false;
			}
		});
		bdMap.setOnMapClickListener(new OnMapClickListener() {

			@Override
			public boolean onMapPoiClick(MapPoi arg0) {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public void onMapClick(LatLng arg0) {
				// TODO Auto-generated method stub
				bdMap.hideInfoWindow();
			}
		});
	}

	@SuppressLint("HandlerLeak")
	private void zhanDianXianShi() {
		// TODO Auto-generated method stub
		new Thread(new Runnable() {

			@Override
			public void run() {
				// 删除本地数据库信息
				bmydb.deleteZhanDianUtil();
				bmydb.deleteZhanDianLocalUtil();
				bmydb.downloadZhanDian();
				drivingSearch(drivintResultIndex);
				Message msgDown = new Message();
				Bundle b = new Bundle();// 存放数据
				b.putInt("result", 2);
				msgDown.setData(b);
				handler.sendMessage(msgDown); // 发送消息
				Log.i("更新车辆数据:", "ok");
			}
		}).start(); // 开启线程

		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				Bundle data = msg.getData();
				int iReturnVal = data.getInt("result");

				Log.i("bus update", "车辆同步结果为-->" + String.valueOf(iReturnVal));
				// UI界面的更新等相关操作
				if (2 == iReturnVal) {
					String msgFinish = "站点查询完成";
					Toast.makeText(getApplicationContext(), msgFinish,
							Toast.LENGTH_SHORT).show();
					List listBuss = null;
					listBuss = bmydb.searchBusList();
					for (int i = 0; i < listBuss.size() / 2; i++) {
						double Latitude = listBuss.get(i).getLat();
						double Longitude = listBuss.get(i).getLng();
						int busid = listBuss.get(i).getZhanDianid();
						BitmapDescriptor bitmap;

						// 构建图标
						bitmap = BitmapDescriptorFactory
								.fromResource(R.drawable.icon_gcoding);

						if (busid == 0) {
							// 构建Marker
							bitmap = BitmapDescriptorFactory
									.fromResource(R.drawable.icon_gcoding);

						}

						LatLng ll = new LatLng(Latitude, Longitude);
						// 构建MarkerOption,用于在地图上添加Marker
						OverlayOptions option = new MarkerOptions()
								.position(ll).icon(bitmap).zIndex(9) // 设置marker所在层级
								.draggable(true); // 设置手势拖拽;
						// 在地图上添加Marker,并显示
						mMakerBus = (Marker) (bdMap.addOverlay(option));

						String strMaker = "maker-zhandian" + String.valueOf(i);

						Bundle bundle = new Bundle();
						bundle.putSerializable("ZhandianUtil", listBuss.get(i));

						mMakerBus.setExtraInfo(bundle);
						Log.d(strMaker, ll.toString());
						makerBus.add(mMakerBus);
						System.out.println("画站点啊啊啊啊啊啊");
						MapStatusUpdate u = MapStatusUpdateFactory
								.newLatLng(ll);
						bdMap.animateMapStatus(u);

						// ll = null;
					}

					isMark = true;
				} else {
					String msgFinish = "站点查询失败";
					Toast.makeText(getApplicationContext(), msgFinish,
							Toast.LENGTH_SHORT).show();
				}
			}
		};

	}

	/**
	 * 路线规划结果回调
	 */
	OnGetRoutePlanResultListener routePlanResultListener = new OnGetRoutePlanResultListener() {

		@Override
		public void onGetWalkingRouteResult(WalkingRouteResult arg0) {
		}

		@Override
		public void onGetTransitRouteResult(TransitRouteResult arg0) {
		}

		@Override
		public void onGetDrivingRouteResult(
				DrivingRouteResult drivingRouteResult) {
			// TODO Auto-generated method stub
			// bdMap.clear();
			if (drivingRouteResult == null
					|| drivingRouteResult.error != SearchResult.ERRORNO.NO_ERROR) {
				Toast.makeText(BusLineSelectActivity.this, "抱歉,未找到结果",
						Toast.LENGTH_SHORT).show();
			}
			if (drivingRouteResult.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) {
				// 起终点或途经点地址有岐义,通过以下接口获取建议查询信息
				// drivingRouteResult.getSuggestAddrInfo()
				return;
			}
			if (drivingRouteResult.error == SearchResult.ERRORNO.NO_ERROR) {
				DrivingRouteOverlay drivingRouteOverlay = new DrivingRouteOverlay(
						bdMap);
				drivingRouteOverlay.setData(drivingRouteResult.getRouteLines()
						.get(drivintResultIndex));// 设置一条驾车路线方案
				bdMap.setOnMarkerClickListener(drivingRouteOverlay);
				drivingRouteOverlay.addToMap();
				drivingRouteOverlay.zoomToSpan();

			}
		}
	};

	/**
	 * 驾车线路查询
	 */
	private void drivingSearch(int index) {
		List zdu = new ArrayList();
		List lu = new ArrayList();
		zdu = bmydb.searchBusList();
		int endn = zdu.size() / 2 - 1;
		System.out.println(endn);
		double lat = zdu.get(0).getLat();
		double lng = zdu.get(0).getLng();
		LatLng stall = new LatLng(lat, lng);
		LatLng endll = new LatLng(zdu.get(endn).getLat(), zdu.get(endn)
				.getLng());
		for (int i = 0; i < zdu.size() / 2; i++) {
			double Latitude = zdu.get(i).getLat();
			double Longitude = zdu.get(i).getLng();
			LatLng ll = new LatLng(Latitude, Longitude);
			PlanNode node = PlanNode.withLocation(ll);
			lu.add(node);
		}
		DrivingRoutePlanOption drivingOption = new DrivingRoutePlanOption();
		drivingOption.from(PlanNode.withLocation(stall));
		drivingOption.to(PlanNode.withLocation(endll));
		drivingOption.passBy(lu);
		routePlanSearch.drivingSearch(drivingOption);// 发起驾车路线规划
	}

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

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

		public void onReceivePoi(BDLocation poiLocation) {
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}


	@Override
	protected void onResume() {
		super.onResume();
		mapView.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
		mapView.onPause();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		poiSearch.destroy();// 释放检索对象资源
		busLineSearch.destroy();// 释放检索对象资源
		mapView.onDestroy();
	}

}

在最后重申我的这几个小问题

1.当调用BaiduMap.OnMapClickListener这个接口时,点击地图时hideInfoWindow出于某种原因可能不起作用

2.点击Marker返回的经纬度可不可以匹配到list里相应的站点,从而获取其站点名称(list里有这些信息)

3.如果不删除数据库文件,情况1在更换路线时还保留之前的站点,clear地图时还会在画出来,情况2显示不是唯一

的primary key

希望能得到帮助,感谢。

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