首先我们需要下载百度SDK包
这个复制在这里
还有百度官方的代码也已经打好了。
自行导入。直接复制全部java,之后粘贴在工程里面
这是布局
布局.xml代码如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3"
android:clickable="true"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="放大"
android:id="@+id/bt_left"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="缩小"
android:id="@+id/bt_center"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="搜索"
android:id="@+id/bt_right"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et_search"
android:hint="输入地点"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
MainActivity
package com.huangfushi.hfs214baiduditu;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.b