如果用百度地图SDK进行地图,定位,导航等相关开发时,需要如下步骤:
1、进入百度地图API官网:http://developer.baidu.com/map/index.php?title=首页,申请key,具体方法详见官网方法;
2、下载你需要的地图,定位,导航SDK和Sample;
3、新建android project,
把libBaiduMapSDK_v_x_x_x.so文件copy进libs中的armeabi文件夹中;把baidumapapi_v_x_x_x.jar放进libs下。
4、编辑AndroidManifest.xml文件:
package名字就是你申请key时用的包名;
增加用户权限设置:
application中添加meta-data,就是放申请key的地方:
5、编辑layout文件:即添加com.baidu.mapapi.MapView:
<span style="font-family:SimSun;font-size:14px;"><RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.baidumap.demo.MainActivity" >
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
/>
</RelativeLayout></span>
6、编辑主activity文件:
<span style="font-family:SimSun;font-size:14px;">public class MainActivity extends Activity {
MapView mMapView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//在使用SDK各组件之前初始化context信息,传入ApplicationContext
//注意该方法要在setContentView方法之前实现
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.main);
mMapView = (MapView) findViewById(R.id.bmapView);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
mMapView.onResume();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mMapView.onPause();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
mMapView.onDestroy();
}</span>
注意的地方已经在代码段中进行了注释!
7、一切完成,貌似可以运行了!并!不!是!
报错了!有木有!
8、解决办法:
添加armeabi-v7a文件夹,copy上述的libBaiduMapSDK_v_x_x_x.so文件;这下程序可以运行!
9、这是为什么呢?
android project中有一个 libs文件夹,此文件夹下包含了armeabi 和armeabi-v7a两个文件夹,我们的c代码编译成的本地库(各种.so)就会放在这两个文件夹其中的一个。那armeabi-v7a 与 armeabi有什么区别,都是什么意思呢?
armeabi和armeabi-v7a是表示cpu的类型,我们知道一般的手机或平板都是用arm的cpu(mips的就悲催的被忽视了),不同的cpu的特性不一样,armeabi就是针对普通的或旧的arm cpu,armeabi-v7a是针对有浮点运算或高级扩展功能的arm cpu。
当然,你同样可以在android.mk里可配置以下宏:
TARGET_CPU_API := armeabi
APP_ABI := armeabi
当你编译时出现一些链接动态库的undefine错误,或你的apk运行时出现装载.so动态库错误时,这个时候你就要想想这个cpu类型的配置是否有误