Andriod studio 学习 之高德地图的使用

本文详细介绍如何使用高德地图API进行路线规划,包括步行、骑行、驾车和公交四种出行方式的路线搜索与显示。通过具体代码示例,展示了如何在Android应用中集成高德地图SDK,实现位置定位、路线搜索及路线展示等功能。
高德地图的使用

首先我们可以在网页搜索高德地图KPI,其中可以帮助我们进行实现高德地图的功能,详细可以参考其中的方法.

效果
代码在这里插入图片描述
代码

布局文件代码

<?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_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp">
        <Button
            android:id="@+id/walk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="步行"
            />
        <Button
            android:id="@+id/ride"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="骑行"
            />
        <Button
            android:id="@+id/driver"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="驾车"
            />
        <Button
            android:id="@+id/bus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="公交"
            />
    </LinearLayout>
    <com.amap.api.maps.MapView
        android:id="@+id/mpa"
        android:layout_weight="9"
        android:layout_width="match_parent"
        android:layout_height="0dp">
    </com.amap.api.maps.MapView>
</LinearLayout>

activity代码

package com.example.work;

import android.Manifest;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.MyLocationStyle;

import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.route.BusPath;
import com.amap.api.services.route.BusRouteResult;
impo
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值