Android Studio integrates Baidu Map SDK

1. It is recommended to read the official inheritance guide of Baidu Maps first, for Eclipse and Android Studio.

Baidu Official Integration Guide

2. Download Baidu Map SDK

Android SDK v4.1.1

There are two types of downloads:

1. One-click download (download all Baidu Map SDK functions)

2. Custom download (combined with your own needs, customize business functions, package and download the selected function development package)

After the download is complete, you will get a file like this

  • The BaiduLAB_Android.jar  file is the jar package that contains all the functions you need
  • Folders such as arm64-v8a  are so files for different mobile phone CPU architectures, which will be used later

3. Integrate into AS

  • Set the AS project directory

  • 1. In the new libs folder under the app folder (there should be by default), copy the BaiduLAB_Android.jar file into
  • 2. Create a new jniLibs folder under the main folder under the src folder, and copy the following folders into

After the above steps, you should be able to see the Project view structure in the above figure

set up gradle

  • In the File menu, select the Project Structure option (project structure) to enter the project structure settings

  • Import BaiduLAB_Android.jar as File dependency

  • After this operation, the dependency in the build.gradle file in your app directory will add this dependency
  • 在你的app目录下的build.gradle文件里新增ndk字段ndk { //选择要添加的对应cpu类型的.so库。 abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a', 'x86', 'x86_64', 'mips', 'mips64'}

5、配置manifest文件

权限配置

 

 <!-- OpenGLES 2.0 -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
    <!--****************一般权限,6.0以上系统不需要额外申请******************-->
    <!-- 用于访问wifi网络信息,wifi信息会用于进行网络定位 -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <!-- 这个权限用于获取wifi的获取权限,wifi信息会用来进行网络定位-->
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <!-- 获取运营商信息,用于支持提供运营商信息相关的接口 -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <!-- 访问网络,网络定位需要上网 -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <!--********************特殊权限,6.0以上系统需要动态申请*******************-->
    <!-- 这个权限用于进行网络定位 -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <!-- 这个权限用于访问GPS定位 -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <!-- 用于读取手机当前的状态 -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <!-- 写入扩展存储,向扩展卡写入数据,用于写入离线定位数据-->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <!-- SD卡读取权限,用户写入离线定位数据-->
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
    <!--地图所需权限-->
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>

 参考官方配置

 

6、修改混淆文件(如果你打开了代码混淆)

这样就成功将百度地图SDK集成到项目中了

7、要想使用百度地图的服务还需要最后一步,申请百度地图AppKey

8、具体显示地图和定位等请参考官方指南hello baiduMap

先初始化:

DemoApplication.java

public class DemoApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
        SDKInitializer.initialize(this);
    }

}

 

    <application
        android:name=".DemoApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.baidu.lbsapi.API_KEY"
            android:value="开发者 key"/>

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326310608&siteId=291194637
Recommended