分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04

一、简介

线路规划支持以下功能:

  • 公交信息查询:可对公交详细信息进行查询;
  • 公交换乘查询:根据起、终点,查询策略,进行线路规划方案;
  • 驾车线路规划:提供不同策略,规划驾车路线;(支持设置途经点)
  • 步行路径检索:支持步行路径的规划。

其中驾车线路规划自v3.4.0版本起支持多线路检索结果的能力。

二、运行截图

简介:介绍公交、驾车和步行三种线路规划方法和自设路线方法。

详述:

(1)驾车查询新增路径点查询功能,具体使用方法详见开发者指南路径规划部分,只需重载接口;

(2)自设路线功能演示开发者如何自己设定一条路线,包括如何设定起点、终点、途径站点和路段;

(3)自设路线功能同时也介绍如何在两个Activity之间切换的时候管理Mapview的生命周期;

(4)可自定义路线的起终点图标;

本示例运行截图如下:

三、设计步骤

1、添加自定义类【代码太多,就不再粘贴在这里了】

本示例用到的文件很多,主要涉及的是自定义覆盖物的相关类,这些文件都在SrcOverlayUtil文件夹下,除了上一节列出的OverlayManager.cs文件和PoiOverlay.cs外,还包括下面的文件。

(1)BikingRouteOverlay.cs文件

用于显示骑行路线的Overlay,自3.4.0版本起可实例化多个添加在地图中显示。

(2)BusLineOverlay.cs文件

用于显示一条公交详情结果的Overlay。

(3)DrivingRouteOverlay.cs文件

用于显示一条驾车路线的overlay,自3.4.0版本起可实例化多个添加在地图中显示,当数据中包含路况数据时,则默认使用路况纹理分段绘制。

(4)TransitRouteOverlay.cs文件

用于显示换乘路线的Overlay,自3.4.0版本起可实例化多个添加在地图中显示。

(5)WalkingRouteOverlay.cs文件

用于显示步行路线的overlay,自3.4.0版本起可实例化多个添加在地图中显示。

2、添加demo13_routeplan.xml文件

在layout文件夹下添加该文件,然后将代码改为下面的内容:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical" >
  6.  
  7. <LinearLayout
  8. xmlns:android="http://schemas.android.com/apk/res/android"
  9. android:layout_width="fill_parent"
  10. android:layout_height="wrap_content"
  11. android:orientation="horizontal" >
  12. <TextView
  13. android:id="@+id/textView1"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:text="起点:" />
  17. <EditText
  18. android:id="@+id/start"
  19. android:layout_width="fill_parent"
  20. android:layout_height="wrap_content"
  21. android:ems="10"
  22. android:text="龙泽" >
  23. <requestFocus />
  24. </EditText>
  25. </LinearLayout>
  26.  
  27. <LinearLayout
  28. xmlns:android="http://schemas.android.com/apk/res/android"
  29. android:layout_width="fill_parent"
  30. android:layout_height="wrap_content"
  31. android:orientation="horizontal" >
  32. <TextView
  33. android:id="@+id/textView2"
  34. android:layout_width="wrap_content"
  35. android:layout_height="wrap_content"
  36. android:text="终点:" />
  37. <EditText
  38. android:id="@+id/end"
  39. android:layout_width="fill_parent"
  40. android:layout_height="wrap_content"
  41. android:ems="10"
  42. android:text="西单" >
  43. <requestFocus />
  44. </EditText>
  45. </LinearLayout>
  46.  
  47. <LinearLayout
  48. xmlns:android="http://schemas.android.com/apk/res/android"
  49. android:layout_width="fill_parent"
  50. android:layout_height="wrap_content"
  51. android:layout_marginBottom="5dip"
  52. android:layout_marginTop="5dip"
  53. android:orientation="horizontal" >
  54. <Button
  55. android:id="@+id/drive"
  56. android:layout_width="fill_parent"
  57. android:layout_height="fill_parent"
  58. android:layout_marginLeft="2dip"
  59. android:layout_marginRight="2dip"
  60. android:layout_weight="1.0"
  61. android:background="@drawable/button_style"
  62. android:text="驾车搜索" />
  63. <Button
  64. android:id="@+id/transit"
  65. android:layout_width="fill_parent"
  66. android:layout_height="fill_parent"
  67. android:layout_marginLeft="2dip"
  68. android:layout_marginRight="2dip"
  69. android:layout_weight="1.0"
  70. android:background="@drawable/button_style"
  71. android:text="公交搜索" />
  72. <Button
  73. android:id="@+id/walk"
  74. android:layout_width="fill_parent"
  75. android:layout_height="fill_parent"
  76. android:layout_marginLeft="2dip"
  77. android:layout_marginRight="2dip"
  78. android:layout_weight="1.0"
  79. android:background="@drawable/button_style"
  80. android:text="步行搜索" />
  81. <Button
  82. android:id="@+id/bike"
  83. android:layout_width="fill_parent"
  84. android:layout_height="fill_parent"
  85. android:layout_marginLeft="2dip"
  86. android:layout_marginRight="2dip"
  87. android:layout_weight="1.0"
  88. android:background="@drawable/button_style"
  89. android:text="骑行搜索" />
  90. </LinearLayout>
  91.  
  92. <RelativeLayout
  93. xmlns:android="http://schemas.android.com/apk/res/android"
  94. android:layout_width="match_parent"
  95. android:layout_height="match_parent" >
  96.  
  97. <com.baidu.mapapi.map.TextureMapView
  98. android:id="@+id/map"
  99. android:layout_width="fill_parent"
  100. android:layout_height="fill_parent"
  101. android:clickable="true" />
  102.  
  103. <LinearLayout
  104. xmlns:android="http://schemas.android.com/apk/res/android"
  105. android:layout_width="wrap_content"
  106. android:layout_height="wrap_content"
  107. android:layout_alignParentRight="true"
  108. android:layout_alignParentTop="true"
  109. android:layout_alignWithParentIfMissing="false"
  110. android:layout_marginRight="10dp"
  111. android:layout_marginTop="10dip"
  112. android:orientation="vertical" >
  113. <Button
  114. android:id="@+id/customicon"
  115. android:layout_width="fill_parent"
  116. android:layout_height="fill_parent"
  117. android:layout_marginTop="10dip"
  118. android:layout_weight="1.0"
  119. android:background="@drawable/button_style"
  120. android:text="自定义起终点图标" />
  121. </LinearLayout>
  122.  
  123. <LinearLayout
  124. xmlns:android="http://schemas.android.com/apk/res/android"
  125. android:layout_width="wrap_content"
  126. android:layout_height="wrap_content"
  127. android:layout_alignParentBottom="true"
  128. android:layout_alignWithParentIfMissing="false"
  129. android:layout_centerHorizontal="true"
  130. android:layout_centerVertical="false"
  131. android:layout_marginBottom="10dip" >
  132.  
  133. <Button
  134. android:id="@+id/pre"
  135. android:layout_width="fill_parent"
  136. android:layout_height="fill_parent"
  137. android:layout_marginLeft="2dip"
  138. android:layout_marginRight="2dip"
  139. android:layout_weight="1.0"
  140. android:background="@drawable/pre_" />
  141.  
  142. <Button
  143. android:id="@+id/next"
  144. android:layout_width="fill_parent"
  145. android:layout_height="fill_parent"
  146. android:layout_marginLeft="2dip"
  147. android:layout_marginRight="2dip"
  148. android:layout_weight="1.0"
  149. android:background="@drawable/next_" />
  150. </LinearLayout>
  151. </RelativeLayout>
  152.  
  153. </LinearLayout>

3、添加Demo13RoutePlan.cs文件

在SrcSdkDemos文件夹下添加该文件,然后将代码改为下面的内容:

  1. using Android.App;
  2. using Android.Content.PM;
  3. using Android.OS;
  4. using Android.Views;
  5. using Android.Widget;
  6. using Com.Baidu.Mapapi.Map;
  7. using Com.Baidu.Mapapi.Model;
  8. using Com.Baidu.Mapapi.Search.Core;
  9. using Com.Baidu.Mapapi.Search.Route;
  10. using BdMapV371Demos.SrcOverlayUtil;
  11.  
  12. namespace BdMapV371Demos.SrcSdkDemos
  13. {
  14. /// <summary>
  15. ///此demo用来展示如何进行驾车、步行、公交路线搜索并在地图使用RouteOverlay、TransitOverlay绘制,
  16. ///同时展示如何进行节点浏览并弹出泡泡。
  17. /// </summary>
  18. [Activity(Label = "@string/demo_name_route",
  19. ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
  20. ScreenOrientation = ScreenOrientation.Sensor)]
  21. public class Demo13RoutePlan : Activity
  22. {
  23. //浏览路线节点相关
  24. Button btnPre = null;//上一个节点
  25. Button btnNext = null;//下一个节点
  26. int nodeIndex = -;//节点索引,供浏览节点时使用
  27. RouteLine route = null;
  28. OverlayManager routeOverlay = null;
  29. bool useDefaultIcon = false;
  30. private TextView popupText = null;//泡泡view
  31.  
  32. //地图相关,使用MyRouteMapView目的是重写touch事件实现泡泡处理。
  33. //如果不处理touch事件,则无需继承,直接使用TextureMapView即可。
  34. TextureMapView mMapView = null; // 地图View
  35. BaiduMap mBaidumap = null;
  36. //搜索相关
  37. RoutePlanSearch mSearch = null; // 搜索模块,也可去掉地图模块独立使用
  38.  
  39. protected override void OnCreate(Bundle savedInstanceState)
  40. {
  41. base.OnCreate(savedInstanceState);
  42. SetContentView(Resource.Layout.demo13_routeplan);
  43.  
  44. //初始化地图
  45. mMapView = FindViewById<TextureMapView>(Resource.Id.map);
  46. mBaidumap = mMapView.Map;
  47.  
  48. btnPre = FindViewById<Button>(Resource.Id.pre);
  49. btnNext = FindViewById<Button>(Resource.Id.next);
  50. btnPre.Visibility = ViewStates.Invisible;
  51. btnNext.Visibility = ViewStates.Invisible;
  52.  
  53. //处理地图点击事件
  54. mBaidumap.MapClick += (s, e) =>
  55. {
  56. //LatLng point = e.P0;
  57. //Toast.MakeText(this, point.ToString(), ToastLength.Long).Show();
  58. mBaidumap.HideInfoWindow();
  59. };
  60.  
  61. //--begin--初始化搜索模块,注册处理事件
  62. mSearch = RoutePlanSearch.NewInstance();
  63. //处理驾车搜索结果
  64. mSearch.GetDrivingRouteResult += (s, e) =>
  65. {
  66. var result = e.P0;
  67. if (result == null || result.Error != SearchResult.ERRORNO.NoError)
  68. {
  69. Toast.MakeText(this, "抱歉,未找到结果", ToastLength.Short).Show();
  70. }
  71. if (result.Error == SearchResult.ERRORNO.AmbiguousRoureAddr)
  72. {
  73. //起终点或途经点地址有岐义,通过result.SuggestAddrInfo属性获取建议查询信息
  74. //......
  75. return;
  76. }
  77. if (result.Error == SearchResult.ERRORNO.NoError)
  78. {
  79. nodeIndex = -;
  80. btnPre.Visibility = ViewStates.Visible;
  81. btnNext.Visibility = ViewStates.Visible;
  82. route = result.RouteLines[];
  83. DrivingRouteOverlay overlay = new MyDrivingRouteOverlay(this, mBaidumap);
  84. routeOverlay = overlay;
  85. mBaidumap.MarkerClick += (sender, args) =>
  86. {
  87. //......
  88. };
  89. overlay.SetData(result.RouteLines[]);
  90. overlay.AddToMap();
  91. overlay.ZoomToSpan();
  92. }
  93. };
  94. //处理公交搜索结果
  95. mSearch.GetTransitRouteResult += (s,e) =>
  96. {
  97. var result = e.P0;
  98. if (result == null || result.Error != SearchResult.ERRORNO.NoError)
  99. {
  100. Toast.MakeText(this, "抱歉,未找到结果", ToastLength.Short).Show();
  101. }
  102. if (result.Error == SearchResult.ERRORNO.AmbiguousRoureAddr)
  103. {
  104. //起终点或途经点地址有岐义,通过以下接口获取建议查询信息
  105. //result.getSuggestAddrInfo()
  106. return;
  107. }
  108. if (result.Error == SearchResult.ERRORNO.NoError)
  109. {
  110. nodeIndex = -;
  111. btnPre.Visibility = ViewStates.Visible;
  112. btnNext.Visibility = ViewStates.Visible;
  113. route = result.RouteLines[];
  114. TransitRouteOverlay overlay = new MyTransitRouteOverlay(this, mBaidumap);
  115. mBaidumap.MarkerClick += (sender, args) =>
  116. {
  117. //......
  118. };
  119. routeOverlay = overlay;
  120. overlay.SetData(result.RouteLines[]);
  121. overlay.AddToMap();
  122. overlay.ZoomToSpan();
  123. }
  124. };
  125. //处理步行搜索结果
  126. mSearch.GetWalkingRouteResult += (s, e) =>
  127. {
  128. var result = e.P0;
  129. if (result == null || result.Error != SearchResult.ERRORNO.NoError)
  130. {
  131. Toast.MakeText(this, "抱歉,未找到结果", ToastLength.Short).Show();
  132. }
  133. if (result.Error == SearchResult.ERRORNO.AmbiguousRoureAddr)
  134. {
  135. //起终点或途经点地址有岐义,通过以下接口获取建议查询信息
  136. //result.getSuggestAddrInfo()
  137. return;
  138. }
  139. if (result.Error == SearchResult.ERRORNO.NoError)
  140. {
  141. nodeIndex = -;
  142. btnPre.Visibility = ViewStates.Visible;
  143. btnNext.Visibility = ViewStates.Visible;
  144. route = result.RouteLines[];
  145. WalkingRouteOverlay overlay = new MyWalkingRouteOverlay(this, mBaidumap);
  146. mBaidumap.MarkerClick += (sender, args) =>
  147. {
  148. //......
  149. };
  150. routeOverlay = overlay;
  151. overlay.SetData(result.RouteLines[]);
  152. overlay.AddToMap();
  153. overlay.ZoomToSpan();
  154. }
  155. };
  156. //处理骑行搜索结果
  157. mSearch.GetBikingRouteResult += (s, e) =>
  158. {
  159. var result = e.P0;
  160. if (result == null || result.Error != SearchResult.ERRORNO.NoError)
  161. {
  162. Toast.MakeText(this, "抱歉,未找到结果", ToastLength.Short).Show();
  163. }
  164. if (result.Error == SearchResult.ERRORNO.AmbiguousRoureAddr)
  165. {
  166. // 如果起终点或途经点地址有岐义,可通过result.SuggestAddrInfo属性获取建议查询信息
  167. //......
  168. return;
  169. }
  170. if (result.Error == SearchResult.ERRORNO.NoError)
  171. {
  172. nodeIndex = -;
  173. btnPre.Visibility = ViewStates.Visible;
  174. btnNext.Visibility = ViewStates.Visible;
  175. route = result.RouteLines[];
  176. BikingRouteOverlay overlay = new MyBikingRouteOverlay(this, mBaidumap);
  177. routeOverlay = overlay;
  178. mBaidumap.MarkerClick += (sender, args) =>
  179. {
  180. //......
  181. };
  182. overlay.SetData(result.RouteLines[]);
  183. overlay.AddToMap();
  184. overlay.ZoomToSpan();
  185. }
  186. };
  187. //--end--初始化搜索模块,注册监听事件
  188.  
  189. //处理【驾车搜素】按钮点击事件
  190. var btnDrive = FindViewById<Button>(Resource.Id.drive);
  191. btnDrive.Click += delegate
  192. {
  193. SearchButtonProcess(Resource.Id.drive);
  194. };
  195.  
  196. //处理【公交搜素】按钮点击事件
  197. var btnTransit = FindViewById<Button>(Resource.Id.transit);
  198. btnTransit.Click += delegate
  199. {
  200. SearchButtonProcess(Resource.Id.transit);
  201. };
  202.  
  203. //处理【步行搜素】按钮点击事件
  204. var btnWalk = FindViewById<Button>(Resource.Id.walk);
  205. btnWalk.Click += delegate
  206. {
  207. SearchButtonProcess(Resource.Id.walk);
  208. };
  209.  
  210. //处理【骑行搜素】按钮点击事件
  211. var btnBike = FindViewById<Button>(Resource.Id.bike);
  212. btnBike.Click += delegate
  213. {
  214. SearchButtonProcess(Resource.Id.bike);
  215. };
  216.  
  217. //处理【自定义起终点图标】按钮点击事件
  218. var btnCustomicon = FindViewById<Button>(Resource.Id.customicon);
  219. btnCustomicon.Click += delegate
  220. {
  221. //切换路线图标,刷新地图使其生效。注意:起终点图标使用中心对齐。
  222. if (routeOverlay == null) return;
  223. if (useDefaultIcon)
  224. {
  225. btnCustomicon.Text = "自定义起终点图标";
  226. Toast.MakeText(this,"将使用系统起终点图标", ToastLength.Short).Show();
  227. }
  228. else
  229. {
  230. btnCustomicon.Text = "系统起终点图标";
  231. Toast.MakeText(this, "将使用自定义起终点图标", ToastLength.Short).Show();
  232. }
  233. useDefaultIcon = !useDefaultIcon;
  234. routeOverlay.RemoveFromMap();
  235. routeOverlay.AddToMap();
  236. };
  237.  
  238. //处理节点浏览相关的按钮事件
  239. btnPre.Click += delegate
  240. {
  241. NodeClick(Resource.Id.pre);
  242. };
  243. btnNext.Click += delegate
  244. {
  245. NodeClick(Resource.Id.next);
  246. };
  247. }
  248.  
  249. /// <summary>
  250. /// 发起路线规划搜索
  251. /// </summary>
  252. /// <param name="id">按钮的id</param>
  253. public void SearchButtonProcess(int id)
  254. {
  255. //重置浏览节点的路线数据
  256. route = null;
  257. btnPre.Visibility = ViewStates.Invisible;
  258. btnNext.Visibility = ViewStates.Invisible;
  259. mBaidumap.Clear();
  260. // 处理搜索按钮响应示例
  261. EditText editSt = FindViewById<EditText>(Resource.Id.start);
  262. EditText editEn = FindViewById<EditText>(Resource.Id.end);
  263. //设置起终点信息,对于tranist search 来说,城市名无意义
  264. PlanNode stNode = PlanNode.WithCityNameAndPlaceName("北京", editSt.Text);
  265. PlanNode enNode = PlanNode.WithCityNameAndPlaceName("北京", editEn.Text);
  266.  
  267. // 实际使用中请对起点终点城市进行正确的设定
  268. if (id == Resource.Id.drive)
  269. {
  270. mSearch.DrivingSearch(new DrivingRoutePlanOption()
  271. .From(stNode).To(enNode));
  272. }
  273. else if (id == Resource.Id.transit)
  274. {
  275. mSearch.TransitSearch(new TransitRoutePlanOption()
  276. .From(stNode).City("北京").To(enNode));
  277. }
  278. else if (id == Resource.Id.walk)
  279. {
  280. mSearch.WalkingSearch(new WalkingRoutePlanOption()
  281. .From(stNode).To(enNode));
  282. }
  283. else if (id == Resource.Id.bike)
  284. {
  285. mSearch.BikingSearch(new BikingRoutePlanOption()
  286. .From(stNode).To(enNode));
  287. }
  288. }
  289.  
  290. /// <summary>
  291. /// 节点浏览示例
  292. /// </summary>
  293. /// <param name="id">按钮的id</param>
  294. public void NodeClick(int id)
  295. {
  296. if (nodeIndex < - || route == null ||
  297. route.AllStep == null || nodeIndex > route.AllStep.Count)
  298. {
  299. return;
  300. }
  301. //设置节点索引
  302. if (id == Resource.Id.next && nodeIndex < route.AllStep.Count - )
  303. {
  304. nodeIndex++;
  305. }
  306. else if (id == Resource.Id.pre && nodeIndex > )
  307. {
  308. nodeIndex--;
  309. }
  310. if (nodeIndex < || nodeIndex >= route.AllStep.Count)
  311. {
  312. return;
  313. }
  314.  
  315. //获取节结果信息
  316. LatLng nodeLocation = null;
  317. string nodeTitle = null;
  318. var step = route.AllStep[nodeIndex];
  319. if (step is DrivingRouteLine.DrivingStep)
  320. {
  321. nodeLocation = ((DrivingRouteLine.DrivingStep)step).Entrance.Location;
  322. nodeTitle = ((DrivingRouteLine.DrivingStep)step).Instructions;
  323. }
  324. else if (step is WalkingRouteLine.WalkingStep)
  325. {
  326. nodeLocation = ((WalkingRouteLine.WalkingStep)step).Entrance.Location;
  327. nodeTitle = ((WalkingRouteLine.WalkingStep)step).Instructions;
  328. }
  329. else if (step is TransitRouteLine.TransitStep)
  330. {
  331. nodeLocation = ((TransitRouteLine.TransitStep)step).Entrance.Location;
  332. nodeTitle = ((TransitRouteLine.TransitStep)step).Instructions;
  333. }
  334.  
  335. if (nodeLocation == null || nodeTitle == null)
  336. {
  337. return;
  338. }
  339. //移动节点至中心
  340. mBaidumap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(nodeLocation));
  341. // Show popup
  342. popupText= new TextView(this);
  343. popupText.SetBackgroundResource(Resource.Drawable.popup);
  344. popupText.SetTextColor(Android.Graphics.Color.Black);
  345. popupText.Text = nodeTitle;
  346. mBaidumap.ShowInfoWindow(new InfoWindow(popupText, nodeLocation, ));
  347. }
  348.  
  349. protected override void OnRestoreInstanceState(Bundle savedInstanceState)
  350. {
  351. base.OnRestoreInstanceState(savedInstanceState);
  352. }
  353.  
  354. //定制RouteOverly
  355. private class MyDrivingRouteOverlay : DrivingRouteOverlay
  356. {
  357. Demo13RoutePlan routePlanDemo;
  358.  
  359. public MyDrivingRouteOverlay(Demo13RoutePlan routePlanDemo, BaiduMap baiduMap) :
  360. base(baiduMap)
  361. {
  362. this.routePlanDemo = routePlanDemo;
  363. }
  364.  
  365. public override BitmapDescriptor GetStartMarker()
  366. {
  367. if (routePlanDemo.useDefaultIcon)
  368. {
  369. return BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_st);
  370. }
  371. return null;
  372. }
  373.  
  374. public override BitmapDescriptor GetTerminalMarker()
  375. {
  376. if (routePlanDemo.useDefaultIcon)
  377. {
  378. return BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_en);
  379. }
  380. return null;
  381. }
  382. }
  383.  
  384. private class MyWalkingRouteOverlay : WalkingRouteOverlay
  385. {
  386. Demo13RoutePlan routePlanDemo;
  387. public MyWalkingRouteOverlay(Demo13RoutePlan routePlanDemo, BaiduMap baiduMap) :
  388. base(baiduMap)
  389. {
  390. this.routePlanDemo = routePlanDemo;
  391. }
  392.  
  393. public new BitmapDescriptor GetStartMarker()
  394. {
  395. if (routePlanDemo.useDefaultIcon)
  396. {
  397. return BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_st);
  398. }
  399. return null;
  400. }
  401.  
  402. public new BitmapDescriptor GetTerminalMarker()
  403. {
  404. if (routePlanDemo.useDefaultIcon)
  405. {
  406. return BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_en);
  407. }
  408. return null;
  409. }
  410. }
  411.  
  412. private class MyTransitRouteOverlay : TransitRouteOverlay
  413. {
  414. Demo13RoutePlan routePlanDemo;
  415.  
  416. public MyTransitRouteOverlay(Demo13RoutePlan routePlanDemo, BaiduMap baiduMap) :
  417. base(baiduMap)
  418. {
  419. this.routePlanDemo = routePlanDemo;
  420. }
  421.  
  422. public override BitmapDescriptor GetStartMarker()
  423. {
  424. if (routePlanDemo.useDefaultIcon)
  425. {
  426. return BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_st);
  427. }
  428. return null;
  429. }
  430.  
  431. public override BitmapDescriptor GetTerminalMarker()
  432. {
  433. if (routePlanDemo.useDefaultIcon)
  434. {
  435. return BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_en);
  436. }
  437. return null;
  438. }
  439. }
  440.  
  441. private class MyBikingRouteOverlay : BikingRouteOverlay
  442. {
  443. Demo13RoutePlan routePlanDemo;
  444. public MyBikingRouteOverlay(Demo13RoutePlan routePlanDemo, BaiduMap baiduMap) : base(baiduMap)
  445. {
  446. this.routePlanDemo = routePlanDemo;
  447. }
  448.  
  449. public new BitmapDescriptor GetStartMarker()
  450. {
  451. if (routePlanDemo.useDefaultIcon)
  452. {
  453. return BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_st);
  454. }
  455. return null;
  456. }
  457.  
  458. public new BitmapDescriptor GetTerminalMarker()
  459. {
  460. if (routePlanDemo.useDefaultIcon)
  461. {
  462. return BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_en);
  463. }
  464. return null;
  465. }
  466. }
  467.  
  468. protected override void OnPause()
  469. {
  470. mMapView.OnPause();
  471. base.OnPause();
  472. }
  473.  
  474. protected override void OnResume()
  475. {
  476. mMapView.OnResume();
  477. base.OnResume();
  478. }
  479.  
  480. protected override void OnDestroy()
  481. {
  482. mSearch.Destroy();
  483. mMapView.OnDestroy();
  484. base.OnDestroy();
  485. }
  486. }
  487. }

4、修改MainActivity.cs

在MainActivity.cs文件的demos字段定义中,去掉【示例13】下面的注释。

运行观察结果。

【Android】3.13 路径规划功能的更多相关文章

  1. 如何用HMS Core位置和地图服务实现附近地点路径规划功能

    日常出行中,路径规划是很重要的部分.用户想要去往某个地点,获取到该地点的所有路径,再根据预估出行时间自行选择合适的路线,极大方便出行.平时生活中也存在大量使用场景,在出行类App中,根据乘客的目的地可 ...

  2. 【BZOJ-3627】路径规划 分层图 + Dijkstra + spfa

    3627: [JLOI2014]路径规划 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 186  Solved: 70[Submit][Status] ...

  3. 机器人自主移动的秘密:SLAM与路径规划有什么关系?(三)

    博客转载自:https://www.leiphone.com/news/201612/lvDXqY82OGNqEiyl.html 雷锋网(公众号:雷锋网)按:本文作者SLAMTEC(思岚科技公号sla ...

  4. BZOJ3627: [JLOI2014]路径规划

    BZOJ3627: [JLOI2014]路径规划 Description 相信大家都用过地图上的路径规划功能,只要输入起点终点就能找出一条最优路线.现在告诉你一张地图的信息,请你找出最优路径(即最短路 ...

  5. 【路径规划】 Optimal Trajectory Generation for Dynamic Street Scenarios in a Frenet Frame (附python代码实例)

    参考与前言 2010年,论文 Optimal Trajectory Generation for Dynamic Street Scenarios in a Frenet Frame 地址:https ...

  6. 基础路径规划算法(Dijikstra、A*、D*)总结

    引言 在一张固定地图上选择一条路径,当存在多条可选的路径之时,需要选择代价最小的那条路径.我们称这类问题为最短路径的选择问题.解决这个问题最经典的算法为Dijikstra算法,其通过贪心选择的步骤从源 ...

  7. Unity路径规划

    Unity路径规划  转自:http://www.cnblogs.com/zsb517/p/4090629.html 背景 酷跑游戏中涉及到弯道.不规则道路. 找来一些酷跑游戏的案例来看,很多都是只有 ...

  8. ROS探索总结(十四)——move_base(路径规划)

    在上一篇的博客中,我们一起学习了ROS定位于导航的总体框架,这一篇我们主要研究其中最重要的move_base包. 在总体框架图中可以看到,move_base提供了ROS导航的配置.运行.交互接口,它主 ...

  9. 全局路径规划算法Dijkstra(迪杰斯特拉算法)- matlab

    参考博客链接:https://www.cnblogs.com/kex1n/p/4178782.html Dijkstra是常用的全局路径规划算法,其本质上是一个最短路径寻优算法.算法的详细介绍参考上述 ...

随机推荐

  1. 几种流行Webservice框架性能对比(转载)

    1摘要 开发webservice应用程序中离不开框架的支持,当open-open网站列举的就有很多种,这对于开发者如何选择带来一定的疑惑.性能Webservice的关键要素,不同的框架性能上存在较大差 ...

  2. Visual Studio使用中的问题

    1.后台断点调试,一到断点的时候就VS已停止 原因:安装插件问题,我的由于安装了" .NET Reflector Visual Studio Extension "插件 解决办法: ...

  3. c-fmt-fn标签用法

      c-fmt-fn标签用法 CreateTime--2017年1月6日15:48:43 Author:Marydon 一.参考链接 http://blog.csdn.net/fmwind/artic ...

  4. SettingsEclipse

      迁移时间--2017年5月20日08:45:07 CreateTime--2016年11月15日11:07:44Author:Marydon --------------------------- ...

  5. 〖Windows〗zigbee实验之cygwin编译tinyos.jar编译出错的解决方法

    1. 使用的cygwin安装包下载地址:cygwin-files.zip 2. 使用的一些rpm安装包的下载地址:cygwin_cc2430_rpms.zip 3. cygwin的默认安装目录是:C: ...

  6. DB2建库简单例子

    --重启数据库 FORCE APPLICATION ALL DB2STOP DB2START --创建数据库 TERRITORY US COLLATE USING SYSTEM ) CONNECT T ...

  7. tomcat在线部署且查看堆栈状态

    配合ab压测tomcat站点的并发量,适当调整JVM参数,堆栈,连接数 00.修改conf/tomcat-user.xml 1. 在$Tomcat_Home/conf/tomcat-users.xml ...

  8. 腾讯云-搭建 Python 开发环境

    搭建 Python 开发环境 准备工作 任务时间:5min ~ 10min Python是一种解释型.面向对象.动态数据类型的高级程序设计语言.首先我们来看看系统中是否已经存在 Python ,并安装 ...

  9. 普通spring jsp+mybatis项目修改为springboot + jsp +mybatis项目

    概述 由于公司决定使用spring cloud,但是公司积累了大量的普通的jsp项目,老的项目直接全部修改为springboot成本过高,周期比较长,而且公司业务正在快速拓展,所以需要把之前的老项目修 ...

  10. Android API之java.lang.String

      boolean java.lang.String.contains(CharSequence cs) String字符串是否包含CharSequence(cs).