1)下载百度地图移动版API(Android)开发包
要在Android应用中使用百度地图API,就需要在工程中引用百度地图API开发包,这个开发包包含两个文件:baidumapapi.jar和libBMapApiEngine.so。下载地址:http://dev.baidu.com/wiki/imap/index.php?title=Android%E5%B9%B3%E5%8F%B0/%E7%9B%B8%E5%85%B3%E4%B8%8B%E8%BD%BD
2)申请API Key
和使用Google map api一样,在使用百度地图API之前也需要获取相应的API Key。百度地图API Key与你的百度账户相关联,因此您必须先有百度帐户,才能获得API Key;并且,该Key与您引用API的程序名称有关。
百度API Key的申请要比Google的简单多了,其实只要你有百度帐号,应该不超过30秒就能完成API Key的申请。申请地址:http://dev.baidu.com/wiki/static/imap/key/
3)创建一个Android工程
这里需要强调一点:百度地图移动版api支持Android 1.5及以上系统,因此我们创建的工程应基于Android SDK 1.5及以上。
工程创建完成后,将baidumapapi.jar和libBMapApiEngine.so分别拷贝到工程的根目录及libs/armeabi目录下,并在工程属性->Java Build Path->Libraries中选择“Add JARs”,选定baidumapapi.jar,这样就可以在应用中使用百度地图API了。工程完整的目录结构如下图所示:
4)在布局文件中添加地图控件(res/layout/main.xml)
-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <com.baidu.mapapi.MapView android:id="@+id/map_View"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:clickable="true"
- />
-
</LinearLayout>
5)创建Activity继承com.baidu.mapapi.MapActivity