android公交车代码,地图定位 绘制公交线路

[android]代码库Button mBtnSearch = null; // 搜索按钮

MapView mMapView = null; // 地图View

MKSearch mSearch = null; // 搜索模块,也可去掉地图模块独立使用

String mCityName = null;

LocationListener loc_listener;

App app = null;

static boolean flag = false;

static Thread thread;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.buslinesearch);

app = (App) this.getApplication();

if (app.mBMapMan == null) {

app.mBMapMan = new BMapManager(getApplication());

app.mBMapMan.init(app.mStrKey, new App.MyGeneralListener());

}

app.mBMapMan.start();

// 如果使用地图SDK,请初始化地图Activity

super.initMapActivity(app.mBMapMan);

mMapView = (MapView) findViewById(R.id.bmapView);

mMapView.setBuiltInZoomControls(true);

// 设置在缩放动画过程中也显示overlay,默认为不绘制

mMapView.setDrawOverlayWhenZooming(true);

mMapView.setBuiltInZoomControls(true);

// 初始化搜索模块,注册事件监听

MapController mMapController = mMapView.getController(); // 得到mMapView的控制权,可以用它控制和驱动平移和缩放

GeoPoint point = new GeoPoint((int) (39.915 * 1E6),

(int) (116.404 * 1E6)); // 用给定的经纬度构造一个GeoPoint,单位是微度 (度 * 1E6)

mMapController.setCenter(point); // 设置地图中心点

mMapController.setZoom(15); // 设置地图zoom级别

mSearch = new MKSearch();

mSearch.init(app.mBMapMan, new MKSearchListener() {

public void onGetPoiResult(MKPoiResult res, int type, int error) {

// 错误号可参考MKEvent中的定义

if (error != 0 || res == null) {

Toast.makeText(BuslineSearch.this, "抱歉,未找到结果",

Toast.LENGTH_LONG).show();

return;

}

// System.out.println(res.toString());

// 找到公交路线poi node

MKPoiInfo curPoi = null;

int totalPoiNum = res.getNumPois();

for (int idx = 0; idx < totalPoiNum; idx++) {

Log.d("busline", "the busline is " + idx);

curPoi = res.getPoi(idx);

if (2 == curPoi.ePoiType) {

break;

}

}

mSearch.busLineSearch(mCityName, curPoi.uid);

}

public void onGetDrivingRouteResult(MKDrivingRouteResult res,

int error) {

}

public void onGetTransitRouteResult(MKTransitRouteResult res,

int error) {

res.getPlan(0).getDistance();

}

public void onGetWalkingRouteResult(MKWalkingRouteResult res,

int error) {

}

public void onGetAddrResult(MKAddrInfo res, int error) {

}

public void onGetBusDetailResult(MKBusLineResult result, int iError) {

if (iError != 0 || result == null) {

Toast.makeText(BuslineSearch.this, "抱歉,未找到结果",

Toast.LENGTH_LONG).show();

return;

}

// result.getBusRoute().get

// result.getBusRoute().getStart().toString();

CustomRouteOverLay routeOverlay = new CustomRouteOverLay(

BuslineSearch.this, mMapView);

// 此处仅展示一个方案作为示例

System.out.println(routeOverlay.size());

routeOverlay.setData(result.getBusRoute());

mMapView.getOverlays().clear();

System.out.println(mMapView.getOverlays().size());

mMapView.getOverlays().add(routeOverlay);

mMapView.invalidate();

mMapView.getController().animateTo(

result.getBusRoute().getStart());

}

@Override

public void onGetSuggestionResult(MKSuggestionResult res, int arg1) {

// TODO Auto-generated method stub

}

});

// mLocationManager.requestLocationUpdates(listener);

// 注册定位事件

loc_listener = new LocationListener() {

@Override

public void onLocationChanged(Location location) {

if (location != null) {

String strLog = String.format("您当前的位置:\r\n" + "纬度:%f\r\n"

+ "经度:%f", location.getLongitude(),

location.getLatitude());

flag = true;

Drawable marker = getResources()

.getDrawable(R.drawable.ic_launcher);

final GeoPoint p = new GeoPoint(

(int) (location.getLatitude() * 1E6),

(int) (location.getLongitude() * 1E6));

CustomOverlayItem item = new CustomOverlayItem(marker,

BuslineSearch.this, p, "我的位置", "", false);

mMapView.getOverlays().add(item);

mMapView.getController().animateTo(p);

}

}

};

// 设定搜索按钮的响应

mBtnSearch = (Button) findViewById(R.id.search);

OnClickListener clickListener = new OnClickListener() {

public void onClick(View v) {

SearchButtonProcess(v);

}

};

mBtnSearch.setOnClickListener(clickListener);

}

void SearchButtonProcess(View v) {

if (mBtnSearch.equals(v)) {

mMapView.getOverlays().clear();

mMapView.getOverlays().removeAll(mMapView.getOverlays());

mMapView.invalidate();

EditText editCity = (EditText) findViewById(R.id.city);

EditText editSearchKey = (EditText) findViewById(R.id.searchkey);

mCityName = editCity.getText().toString();

mSearch.poiSearchInCity(mCityName, editSearchKey.getText()

.toString());

}

}

@Override

protected void onPause() {

if (null == app)

app = (App) this.getApplication();

app.mBMapMan.getLocationManager().removeUpdates(loc_listener);

app.mBMapMan.stop();

super.onPause();

}

@Override

protected void onResume() {

if (null == app)

app = (App) this.getApplication();

app.mBMapMan.start();

super.onResume();

app.mBMapMan.getLocationManager().requestLocationUpdates(loc_listener);// 定位

}

@Override

protected boolean isRouteDisplayed() {

// TODO Auto-generated method stub

return false;

}

@Override

protected void onDestroy() {

// TODO Auto-generated method stub

super.onDestroy();

}

[源代码打包下载]

694748ed64b9390909c0d88230893790.png

【6层】一字型框架办公楼(含建筑结构图、计算书) 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值