Andriod studio 学习 之 高德地图的导航功能

本文介绍如何使用高德地图API在Android应用中实现导航功能,包括步行、骑行、自驾和货车导航。通过XML布局定义UI元素,如输入框和按钮,并在activity文件中进行事件绑定和路线计算。
实现效果

具体可以参考搜索高德地图API的一些介绍,添加清单文件以及依赖
高德官方API:https://lbs.amap.com/api/android-navi-sdk/summary/
在这里插入图片描述

代码

布局xml

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".Main2Activity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


            <EditText
                android:id="@+id/start_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="起点" />

            <EditText
                android:id="@+id/end_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="终点" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <Button
                android:id="@+id/walk_btu"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="步行导航" />

            <Button
                android:id="@+id/ride_btu"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="骑行导航" />

            <Button
                android:id="@+id/by_btu"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="自驾导航" />
            <Button
                android:id="@+id/truck_btu"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="货车导航" />
        </LinearLayout>
    </LinearLayout>

    <com.amap.api.navi.AMapNaviView

        android:id="@+id/map"

        android:layout_width="match_parent"

        android:layout_height="match_parent" />
</LinearLayout>

activity文件

    package com.example.maps;

import android.support.v7.app.AppCompatActivi
评论 10
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值