高德
所有功能 官网都有解释
导入依赖
implementation 'com.amap.api:map2d:latest.integration'
implementation 'com.amap.api:search:latest.integration'
布局
<?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"
tools:context=".MainActivity"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_bg"
android:hint="我的位置"
android:layout_marginTop="3dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="60dp"
android:paddingLeft="5dp"
android:id="@+id/my_location"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_bg"
android:hint="终点"
android:layout_marginLeft="30dp"
android:layout_marginTop="3dp"
android:paddingLeft="5dp"
android:layout_weight="1"
android:id="@+id/my_destination"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="搜索"
android:layout_weight="6"
android:gravity="center"
android:id="@+id/my_search"
android:background="@drawable/txt_bg"
android:layout_marginLeft="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="步行"
android:padding="3dp"
android:background="@drawable/txt_bg"
android:layout_marginLeft="30dp"
android:id="@+id/walk"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="驾车"
android:padding="3dp"
android:background="@drawable/txt_bg"
android:id="@+id/driver"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="公交"
android:padding="3dp"
android:background="@drawable/txt_bg"
android:id="@+id/bus"/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="3dp"
android:divider="#B9B6B6"
android:visibility="gone"
android:id="@+id/my_list">
</ListView>
<com.amap.api.maps2d.MapView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/my_MapView">
</com.amap.api.maps2d.MapView>
</LinearLayout>
list的Item布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/item_txt"
android:textSize="18sp"/>
</LinearLayout>
适配器
public class MyListAdapter extends BaseAdapter {
ArrayList<PoiItem> arrayList;
Context context;
public MyListAdapter(ArrayList<PoiItem> arrayList, Context context) {
this.arrayList = arrayList;
this.context = context;
}
@Override
public int getCount() {
return arrayList.size