百度地图--路线(步行)
来源:互联网 发布:wps输入数据自动计算 编辑:程序博客网 时间:2024/04/30 20:43
Button mBtnPre = null; // 上一个节点 Button mBtnNext = null; // 下一个节点 int nodeIndex = -1; // 节点索引,供浏览节点时使用 RouteLine route = null; WalkingRouteOverlay routeOverlay = null; boolean useDefaultIcon = false; private TextView popupText = null; // 泡泡view // 地图相关,使用继承MapView的MyRouteMapView目的是重写touch事件实现泡泡处理 // 如果不处理touch事件,则无需继承,直接使用MapView即可 MapView mMapView = null; // 地图View BaiduMap mBaidumap = null; // 搜索相关 RoutePlanSearch mSearch = null; // 搜索模块,也可去掉地图模块独立使用 TransitRouteResult nowResult = null; DrivingRouteResult nowResultd = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { SDKInitializer.initialize(getApplicationContext()); } catch (Exception e) { // TODO: handle exception ToastUtils.shortToast(getApplicationContext(), "地图api初始化失败"); return; } setContentView(R.layout.activity_lu_xian_map); initSystemBar(this); initTitle();// // 初始化地图 mMapView = (MapView) findViewById(R.id.map); mBaidumap = mMapView.getMap(); mBtnPre = (Button) findViewById(R.id.pre); mBtnNext = (Button) findViewById(R.id.next); mBtnPre.setVisibility(View.INVISIBLE); mBtnNext.setVisibility(View.INVISIBLE); // 地图点击事件处理 mBaidumap.setOnMapClickListener(this); // 初始化搜索模块,注册事件监听// mSearch = RoutePlanSearch.newInstance();// mSearch.setOnGetRoutePlanResultListener(this);// searchButtonProcess(); new Thread(new Runnable() { @Override public void run() { try { Thread.currentThread().sleep(5000);//阻断2秒 } catch (InterruptedException e) { e.printStackTrace(); } } }).start(); // 天安门坐标 double mLat1 = 39.915291; double mLon1 = 116.403857; // 百度大厦坐标 double mLat2 = 40.056858; double mLon2 = 116.308194; LatLng loc_start = new LatLng(mLat1, mLon1); LatLng loc_end = new LatLng(mLat2, mLon2); mSearch = RoutePlanSearch.newInstance(); mSearch.setOnGetRoutePlanResultListener(this); PlanNode stNode = PlanNode.withLocation(loc_start); PlanNode enNode = PlanNode.withLocation(loc_end); mSearch.walkingSearch((new WalkingRoutePlanOption()).from(stNode).to(enNode)); }/** * 节点浏览示例 * * @param v */public void nodeClick(View v) { if (route == null || route.getAllStep() == null) { return; } if (nodeIndex == -1 && v.getId() == R.id.pre) { return; } // 设置节点索引 if (v.getId() == R.id.next) { if (nodeIndex < route.getAllStep().size() - 1) { nodeIndex++; } else { return; } } else if (v.getId() == R.id.pre) { if (nodeIndex > 0) { nodeIndex--; } else { return; } } // 获取节结果信息 LatLng nodeLocation = null; String nodeTitle = null; Object step = route.getAllStep().get(nodeIndex); if (step instanceof DrivingRouteLine.DrivingStep) { nodeLocation = ((DrivingRouteLine.DrivingStep) step).getEntrance().getLocation(); nodeTitle = ((DrivingRouteLine.DrivingStep) step).getInstructions(); } else if (step instanceof WalkingRouteLine.WalkingStep) { nodeLocation = ((WalkingRouteLine.WalkingStep) step).getEntrance().getLocation(); nodeTitle = ((WalkingRouteLine.WalkingStep) step).getInstructions(); } else if (step instanceof TransitRouteLine.TransitStep) { nodeLocation = ((TransitRouteLine.TransitStep) step).getEntrance().getLocation(); nodeTitle = ((TransitRouteLine.TransitStep) step).getInstructions(); } else if (step instanceof BikingRouteLine.BikingStep) { nodeLocation = ((BikingRouteLine.BikingStep) step).getEntrance().getLocation(); nodeTitle = ((BikingRouteLine.BikingStep) step).getInstructions(); } if (nodeLocation == null || nodeTitle == null) { return; } // 移动节点至中心 mBaidumap.setMapStatus(MapStatusUpdateFactory.newLatLng(nodeLocation)); // show popup popupText = new TextView(LuXianMapActivity.this); popupText.setBackgroundResource(R.drawable.popup); popupText.setTextColor(0xFF000000); popupText.setText(nodeTitle); mBaidumap.showInfoWindow(new InfoWindow(popupText, nodeLocation, 0));}@Overridepublic void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState);}@Overridepublic void onGetWalkingRouteResult(WalkingRouteResult result) { if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) { Toast.makeText(LuXianMapActivity.this, "抱歉,未找到结果", Toast.LENGTH_SHORT).show(); } if (result.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) { // 起终点或途经点地址有岐义,通过以下接口获取建议查询信息 // result.getSuggestAddrInfo() return; } if (result.error == SearchResult.ERRORNO.NO_ERROR) { nodeIndex = -1; mBtnPre.setVisibility(View.VISIBLE); mBtnNext.setVisibility(View.VISIBLE); route = result.getRouteLines().get(0); WalkingRouteOverlay overlay = new MyWalkingRouteOverlay(mBaidumap); mBaidumap.setOnMarkerClickListener(overlay); routeOverlay = overlay; overlay.setData(result.getRouteLines().get(0)); overlay.addToMap(); overlay.zoomToSpan(); }}private class MyWalkingRouteOverlay extends WalkingRouteOverlay { public MyWalkingRouteOverlay(BaiduMap baiduMap) { super(baiduMap); } @Override public BitmapDescriptor getStartMarker() { if (useDefaultIcon) { return BitmapDescriptorFactory.fromResource(R.drawable.icon_st); } return null; } @Override public BitmapDescriptor getTerminalMarker() { if (useDefaultIcon) { return BitmapDescriptorFactory.fromResource(R.drawable.icon_en); } return null; }}@Overridepublic void onMapClick(LatLng point) { mBaidumap.hideInfoWindow();}@Overridepublic boolean onMapPoiClick(MapPoi poi) { return false;}@Overrideprotected void onPause() { mMapView.onPause(); super.onPause();}@Overrideprotected void onResume() { mMapView.onResume(); super.onResume();}@Overrideprotected void onDestroy() { mSearch.destroy(); mMapView.onDestroy(); super.onDestroy();}// 响应DLg中的List item 点击interface OnItemInDlgClickListener { public void onItemClick(int position);}
0 0
- 百度地图--路线(步行)
- 百度地图步行箭头和路线一致
- 百度地图:加强篇(路线检索:驾车+步行+公交换乘)
- 搭建百度地图,步行路线、反地理编码等应用
- 百度地图api实现路线规划之步行驾车
- Android学习笔记之百度地图(驾车路线搜索及RouteOverlay步行路线搜索及RouteOverlay)
- Android学习笔记之百度地图(驾车路线搜索及RouteOverlay步行路线搜索及RouteOverlay)
- Android学习笔记之百度地图(驾车路线搜索及RouteOverlay步行路线搜索及RouteOverlay)
- Android学习笔记之百度地图(驾车路线搜索及RouteOverlay步行路线搜索及RouteOverlay)
- android百度地图开发V4.5最新版(5)---路线规划问题步行,骑车,公交,驾车等。
- 高德地图-添加路线规划(自驾、步行...)
- 高德地图 步行路线规划 Walking
- Android 高德地图 步行 路线规划
- BaiduMap---百度地图官方Demo之路径规划功能(介绍公交,驾车和步行三种线路规划方法和自设路线方法)
- Android百度地图——路径规划(驾车、步行和公交线路搜索)
- Android百度地图 - 路径规划(驾车、步行和公交线路搜索)
- Android 百度地图 SDK v3_3_0 (六) ---驾车、步行、公交路线搜索
- 百度地图导航的接入(包含三种选择方式驾车、公交、步行)
- PHP中字符串类型与数值类型混合计算
- dubbo服务只注册不订阅
- 利用tableau数据可视化工具创建圆环图——初入门篇
- 怎么去理解Spring Aop
- 用git与github建立连接
- 百度地图--路线(步行)
- C语言----链表
- android 控件 recyclerview
- (iOS开发)计算时间差
- mybatis学习(3)---加载配置文件
- Android中解决复写ListView时出现OnScollListener无法监听,这时如果实现标题栏渐变色的话,应该将计算滚动距离的方法,写在不断调用的回调中。
- 洛谷 P1372 又是毕业季I
- android View长按事件简单写法
- 近期开发中用到的一些东西(关于自适应大小,字符串处理,心跳,本地推送,json处理等)