接上一篇:
http://blog.csdn.net/user11223344abc/article/details/78154357
1.集成前想想
申请了半天,感觉累累哒,迫不及待的就想看见点什么,于是开始集成,集成就涉及到一个问题,百度地图sdk都是分模块的,那么我思考我的大体目标是:
- 基础地图:基本展示,隐藏地图右下角加减号,将距离比例尺调小…
- 全量定位:包含基础,离线,室内…
- 云检索:poi…
- 周边雷达:附近的xxx
- 覆盖物&路径规划:marker,overlay,infowindow…点击事件,将当前定位设为锚点,进行路径规划,然后点击地图空白部分解开锚点,进行下一次的以上操作
- 全景图:扩展功能咯
2.于是我就去下载了这么一窝子sdk的lib库(密集恐惧症 o.O):
3.下载完成了:
4.copy到项目
5.MainActivity布局文件定义mapView,及其初始化:
layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="zj.shitmap.MainActivity">
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
</RelativeLayout>
初始化:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
private MapView mBaiduMap;
//在使用SDK各组件之前初始化context信息,传入ApplicationContext
//注意该方法要再setContentView方法之前实现
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);
mBaiduMap = findViewById(R.id.bmapView);
//6.0+拿权限
getPersimmions();
}
getPersimmions(),6.0+定位是需要权限的,先写在这里,跑helloword炸会很影响积极性
private final int SDK_PERMISSION_REQUEST = 127;
@TargetApi(23)
private void getPersimmions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ArrayList<String> permissions = new ArrayList<String>();
/***
* 定位权限为必须权限,用户如果禁止,则每次进入都会申请
*/
// 定位精确位置
if(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
}
if(checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED){
permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
}
/*
* 读写权限和电话状态权限非必要权限(建议授予)只会申请一次,用户同意或者禁止,只会弹一次
*/
// 读写权限
if (addPermission(permissions, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// permissionInfo += "Manifest.permission.WRITE_EXTERNAL_STORAGE Deny \n";
}
// 读取电话状态权限
if (addPermission(permissions, Manifest.permission.READ_PHONE_STATE)) {
// permissionInfo += "Manifest.permission.READ_PHONE_STATE Deny \n";
}
if (permissions.size() > 0) {
requestPermissions(permissions.toArray(new String[permissions.size()]), SDK_PERMISSION_REQUEST);
}
}
}
@TargetApi(23)
private boolean addPermission(ArrayList<String> permissionsList, String permission) {
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { // 如果应用没有获得对应权限,则添加到列表中,准备批量申请
if (shouldShowRequestPermissionRationale(permission)){
return true;
}else{
permissionsList.add(permission);
return false;
}
}else{
return true;
}
}
@TargetApi(23)
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
// TODO Auto-generated method stub
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
6.Run,走你,天安门见:
7.demo下载:
http://download.csdn.net/download/user11223344abc/10007991