0

0

【Android】第3章(14)路径规划功能

php中文网

php中文网

发布时间:2016-07-06 13:30:23

|

1196人浏览过

|

来源于php中文网

原创

分类:c#、android、vs2015、百度地图应用; 创建日期:2016-02-04 一、简介 线路规划支持以下功能: 公交信息查询:可对公交详细信息进行查询; 公交换乘查询:根据起、终点,查询策略,进行线路规划方案; 驾车线路规划:提供不同策略,规划驾车路线;(支

分类:c#、android、vs2015、百度地图应用; 创建日期:2016-02-04

一、简介

线路规划支持以下功能:

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

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

二、运行截图

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

详述:

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

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

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

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

本示例运行截图如下:

image

三、设计步骤

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

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

(1)BikingRouteOverlay.cs文件

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

(2)BusLineOverlay.cs文件

FaceSwapper
FaceSwapper

FaceSwapper是一款AI在线换脸工具,可以让用户在照片和视频中无缝交换面孔。

下载

用于显示一条公交详情结果的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文件夹下添加该文件,然后将代码改为下面的内容:

xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="起点:" />
        <EditText
            android:id="@+id/start"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:text="龙泽" >
            <requestFocus />
        EditText>
    LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="终点:" />
        <EditText
            android:id="@+id/end"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:text="西单" >
            <requestFocus />
        EditText>
    LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dip"
        android:layout_marginTop="5dip"
        android:orientation="horizontal" >
        <Button
            android:id="@+id/drive"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="2dip"
            android:layout_marginRight="2dip"
            android:layout_weight="1.0"
            android:background="@drawable/button_style"
            android:text="驾车搜索" />
        <Button
            android:id="@+id/transit"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="2dip"
            android:layout_marginRight="2dip"
            android:layout_weight="1.0"
            android:background="@drawable/button_style"
            android:text="公交搜索" />
        <Button
            android:id="@+id/walk"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="2dip"
            android:layout_marginRight="2dip"
            android:layout_weight="1.0"
            android:background="@drawable/button_style"
            android:text="步行搜索" />
        <Button
            android:id="@+id/bike"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="2dip"
            android:layout_marginRight="2dip"
            android:layout_weight="1.0"
            android:background="@drawable/button_style"
            android:text="骑行搜索" />
    LinearLayout>

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

       <com.baidu.mapapi.map.TextureMapView
            android:id="@+id/map"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:clickable="true" />

       <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="false"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dip"
            android:orientation="vertical" >
            <Button
                android:id="@+id/customicon"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginTop="10dip"
                android:layout_weight="1.0"
                android:background="@drawable/button_style"
                android:text="自定义起终点图标" />
        LinearLayout>

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignWithParentIfMissing="false"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="false"
            android:layout_marginBottom="10dip" >

            <Button
                android:id="@+id/PRe"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:layout_weight="1.0"
                android:background="@drawable/pre_" />

            <Button
                android:id="@+id/next"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:layout_weight="1.0"
                android:background="@drawable/next_" />
        LinearLayout>
    RelativeLayout>

LinearLayout>

3、添加Demo13RoutePlan.cs文件

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

using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Views;
using Android.Widget;
using Com.Baidu.Mapapi.Map;
using Com.Baidu.Mapapi.Model;
using Com.Baidu.Mapapi.Search.Core;
using Com.Baidu.Mapapi.Search.Route;
using BdMapV371Demos.SrcOverlayUtil;

namespace BdMapV371Demos.SrcSdkDemos
{
    /// 
    ///此demo用来展示如何进行驾车、步行、公交路线搜索并在地图使用RouteOverlay、TransitOverlay绘制,
    ///同时展示如何进行节点浏览并弹出泡泡。
    /// 
    [Activity(Label = "@string/demo_name_route",
        ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
        ScreenOrientation = ScreenOrientation.Sensor)]
    public class Demo13RoutePlan : Activity
    {
        //浏览路线节点相关
        Button btnPre = null;//上一个节点
        Button btnNext = null;//下一个节点
        int nodeIndex = -2;//节点索引,供浏览节点时使用
        RouteLine route = null;
        OverlayManager routeOverlay = null;
        bool useDefaultIcon = false;
        private TextView popupText = null;//泡泡view

        //地图相关,使用MyRouteMapView目的是重写touch事件实现泡泡处理。
        //如果不处理touch事件,则无需继承,直接使用TextureMapView即可。
        TextureMapView mMapView = null;   // 地图View
        BaiduMap mBaidumap = null;
        //搜索相关
        RoutePlanSearch mSearch = null;    // 搜索模块,也可去掉地图模块独立使用

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.demo13_routeplan);

            //初始化地图
            mMapView = FindViewById(Resource.Id.map);
            mBaidumap = mMapView.Map;

            btnPre = FindViewById

4、修改MainActivity.cs

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

运行观察结果。


相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
go语言 注释编码
go语言 注释编码

本专题整合了go语言注释、注释规范等等内容,阅读专题下面的文章了解更多详细内容。

2

2026.01.31

go语言 math包
go语言 math包

本专题整合了go语言math包相关内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

go语言输入函数
go语言输入函数

本专题整合了go语言输入相关教程内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

golang 循环遍历
golang 循环遍历

本专题整合了golang循环遍历相关教程,阅读专题下面的文章了解更多详细内容。

0

2026.01.31

Golang人工智能合集
Golang人工智能合集

本专题整合了Golang人工智能相关内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

2026赚钱平台入口大全
2026赚钱平台入口大全

2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。

76

2026.01.31

高干文在线阅读网站大全
高干文在线阅读网站大全

汇集热门1v1高干文免费阅读资源,涵盖都市言情、京味大院、军旅高干等经典题材,情节紧凑、人物鲜明。阅读专题下面的文章了解更多详细内容。

73

2026.01.31

无需付费的漫画app大全
无需付费的漫画app大全

想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。

67

2026.01.31

漫画免费在线观看地址大全
漫画免费在线观看地址大全

想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。

19

2026.01.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Excel 教程
Excel 教程

共162课时 | 14.7万人学习

Java 教程
Java 教程

共578课时 | 54.2万人学习

Uniapp从零开始实现新闻资讯应用
Uniapp从零开始实现新闻资讯应用

共64课时 | 6.7万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号