All Products
Search
Document Center

Mobile Platform as a Service:Use Baidu Map in Mini Program

Last Updated:Feb 07, 2025

Introduce Baidu Map SDK

Refer to Baidu Map official documentation to integrate the Map LBS SDK. Ensure the SDK version is 7.5.9 or higher. After adding the SDK, you must delete the libc++_shared.so file to prevent conflicts with mPaas.

Configure Baidu Map API Key in AndroidManifest.xml

Insert the following code into <application> to set up the developer key (AK), or dynamically configure the AK by SDKInitializer.setApiKey("ak").

<application>  
    <meta-data  
        android:name="com.baidu.lbsapi.API_KEY"  
        android:value="developer key" />  
</application>

Initialize Baidu Map and set coordinate system

// After agreeing to the App privacy, set the map privacy protocol
SDKInitializer.setAgreePrivacy(this, true);
// After agreeing to the App privacy, set the Baidu location privacy protocol
LocationClient.setAgreePrivacy(true);
// Initialize context information before using SDK components, passing in ApplicationContext
SDKInitializer.initialize(this);
// Since version 4.3.0, all interfaces of Baidu Map SDK support both Baidu coordinates and National Survey Bureau coordinates. Use this method to set the coordinate type you use.
// Including BD09LL and GCJ02 coordinates, the default is BD09LL coordinates.
SDKInitializer.setCoordType(CoordType.GCJ02);

Configure the mini program to use Baidu Map

Mriver.setConfig("ta_map_type","2");