Android 百度地图学习笔记--公交路线查询

来源:互联网 发布:有淘宝优惠券的app 编辑:程序博客网 时间:2024/04/26 23:09

其实公交路线查询是在POI检索的基础上来开发的,首先你输入公交路线(这也是一个兴趣点),检索出来之后,会判断检索结果中的结果是不是公交路线,是的话再继续操作。
POI检索过程就不说了,直接来对结果进行处理吧。
1.`public void onGetPoiResult(PoiResult result) {

    if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {        Toast.makeText(BusLineSearchDemo.this, "抱歉,未找到结果",                Toast.LENGTH_LONG).show();        return;    }    // 遍历所有poi,找到类型为公交线路的poi    busLineIDList.clear();    for (PoiInfo poi : result.getAllPoi()) {        if (poi.type == PoiInfo.POITYPE.BUS_LINE                || poi.type == PoiInfo.POITYPE.SUBWAY_LINE) {            busLineIDList.add(poi.uid);        }    }    SearchNextBusline(null);    route = null;}`

2.对路线的没个节点进行浏览

public void nodeClick(View v) {        if (nodeIndex < -1 || route == null                || nodeIndex >= route.getStations().size())            return;        TextView popupText = new TextView(this);        popupText.setBackgroundResource(R.drawable.popup);        popupText.setTextColor(0xff000000);        // 上一个节点        if (mBtnPre.equals(v) && nodeIndex > 0) {            // 索引减            nodeIndex--;        }        // 下一个节点        if (mBtnNext.equals(v) && nodeIndex < (route.getStations().size() - 1)) {            // 索引加            nodeIndex++;        }        if(nodeIndex >= 0){            // 移动到指定索引的坐标            mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(route                    .getStations().get(nodeIndex).getLocation()));            // 弹出泡泡            popupText.setText(route.getStations().get(nodeIndex).getTitle());            mBaiduMap.showInfoWindow(new InfoWindow(popupText, route.getStations()                    .get(nodeIndex).getLocation(), 0));        }    }

3打完收工

0 0
原创粉丝点击