实现效果
具体可以参考搜索高德地图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

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





