How to Integrate Baidu maps in Android Apps
Well, well, well.. Chinese IT Market is still more relevant today than ever. Remember, in one of our episodes, we already talked about mobile and web development for China. So if you are looking how to launch an app in China, you definitely need to take a look at it.
It’s common knowledge in China you have to stay connected to VPN if you want to use your apps via Google. But, our favorite, Google Maps, is not so accurate in China. In this case, Baidu Maps is a great alternative. Baidu Maps is available in those places where Google Maps is not. Another cool advantage is its ability to download and use maps offline. Tourists are able to create their own travel maps where they can mark places visited or a wishlist for the future.
Our developers do theiк best to meet all the users requirements and make apps as user-friendly as possible.
In this episode, we’re going to share with you our own experience about integrating Baidu Maps in an Android app.
Make yourself a cup of tea, sit down, and enjoy your trip to Baidu Maps Integration.
Register App
First, if we want to start working with Baidu services, we need to register the application:
https://passport.baidu.com/v2/?login
Having registered, we need to get a developer key.
Adding API
We need to install SDK. Follow the link below:
http://lbsyun.baidu.com/index.php?title=androidsdk/sdkandev-download
As you can see, Baidu offers various development services.We need to choose those services necessary for us:
We download SDK and add it into the project. Additionally, we need to create a folder for the native libraries. For this, add the following in the build.gradle:
Add it to the folder jniLibs:
Don’t forget to compile it. Then, check the following line in the build.gradle:
Having compiled and built the project, initialize SDK in the Application class:
Great news! You’ve successfully installed SDK in the project! The next step is displaying a map.
Create Map
First, specify a developer key in the file’s manifest:
Don’t forget about the necessary permissions:
Add mapView into the layout:
In the activity inflate map layout and handle its lifecycle:
Map View has 3 types of mapping mode:
MAP_TYPE_NORMAL - General map (including 3D maps)MAP_TYPE_SATELLITE - Satellite imageryMAP_TYPE_NONE - Blank map
Then, compile it all and run:

Interact with Map
To zoom the map:
The next step is to set the logo position of the Baidu:
Install a compass:
Enable scroll:
Enable zoom gestures:
Enable map rotation:
Block all gestures:
Handle clicks:
Draw on the Map
Baidu maps allows adding markers, drawing lines and figures as well as adding text information to the map.
Add a marker:

Add a line:

Add a polygon:

Add text:

Geocoding
One of the problems you can solve using Baidu maps is geocoding. Basically, geocoding allows getting the information about the address according to given coordinates. That’s why there’s a class GeoCoder in the SDK:
Adding data processing with the help of OnGetGeoCoderResultListener is necessary. In the methods onGetGeoCodeResult(), onGetReverseGeoCodeResult(), we process the result:
Having the result, we “destroy” the GeoCoder:
The Bottom Line
Yaay! You made it! As you can see, the integration of Baidu services in Android applications doesn’t take much time. Our trip to the Baidu Maps Integration for Androird has come to an end. Hopefully, you’ve learned something new, and our article has helped you to develop your app.