“This is the 21st day of my participation in the August Text Challenge.
Welcome friends to search “Andy Hui” on wechat to pay attention to a wave!
Write some thoughts of the programmer, hope it will help you.
Baidu Map development – build the foundation scaffolding 01 (QQ.com)
01 Build basic scaffolding
Due to work needs, recently in the Android version of Baidu map SDK, carefully read its public documents (official tutorial), just want to say: Baidu’s tutorial is great, write very not easy to understand, novice according to the document to operate will encounter all kinds of pits, it is difficult to achieve its simple map function. Moreover, the document has not been updated for a long time, and many methods and variables in the MAP SDK have been abandoned. Anyway, it is difficult to work out smoothly according to the official tutorial.
In their own exploration and exploration, completed the Android version of baidu map of the conventional development business. Recently I was thinking of writing a basic tutorial, so that beginners can reference this tutorial to avoid a lot of pitfalls, but also quickly get started to implement its basic functions, put more energy into the business logic, I hope this tutorial can help you.
Understand the basics
Baidu map SDK address: lbsyun.baidu.com/index.php?t…
Baidu address a SDK: lbsyun.baidu.com/index.php?t…
Baidu Map is the leader in the domestic map industry at present. Due to its wide coverage, high precision, stable system and large user base, many developers choose Baidu Map as the third party low-level map function of the project from the very beginning.
Baidu Map SDK is divided into a variety of development packages, including Android SDK, IOS SDK and Web development SDK, which can meet the needs of users in multiple scenarios.
Although baidu map document operation up all kinds of invisible pit, but if the novice want to fully understand baidu map or need to start from scratch carefully read, very helpful for late business development (after all, is the official writing, some technical points or listed).
First: focus on the main understanding of the development guide, which for the map implementation details are described.
Secondly, read the common problems in the above pictures carefully. When you follow the tutorial, 80% of the bugs you encounter can be found in the FAQ bar.
Third: in the sample center, you can download to the current official Baidu Demo code, you can download according to the business you need to achieve to learn.
At the end of this tutorial I will upload the code to Gitee and Github for you to download and learn on your own.
You can also pay attention to my original public number [Andy Hui], get the corresponding source code, exchange and learning.
To achieve baidu map nested use, must follow the following steps to operate.
- Register and apply for keys
In fact, registered Baidu account, application to become a Baidu developer, in the subsequent development process, for each need to use Baidu map software, need to apply for a key in Baidu map, can be normally loaded and accessed.
- Download the specific SDK and introduce it into the specific project
Baidu Map encapsulates and integrates its own resources and codes into a specific SDK. If we want to realize the function of Baidu Map, we must first download the corresponding SDK and successfully introduce it into the project.
- Configure the environment associated with the map in the project
Configure its specific environment so that baidu Map SDK can work properly, otherwise Baidu Map can not be applied in Android projects.
1. Register and apply for keys
Baidu map tutorial in the “obtain key >>” column and [Development guide – project creation – registration and obtain key] in a separate page to describe.
Tutorial: lbsyun.baidu.com/index.php?t…
Baidu map SDK development key application address is: lbs.baidu.com/apiconsole/…
Before using the SDK, developers need to obtain baidu Map Mobile Development Key (AK), which is associated with your Baidu account. Please keep your AK safe, it will be used for map initialization.
You can follow the above requirements to register and apply for the following:
- Apply for a Baidu account first and log in.
-
Log in to the API console.
-
Click “Create Application” to apply for the development key.
- Enter the application name, select Android SDK for the application type, and enter SHA1 and the package name correctly. For details about how to obtain SHA1 and the package name, see the following. As shown in figure:
The prerequisite of application is that you have a working Android project, because you need to use the AppliacationID value here. You can refer to the official documents provided by Baidu to operate the process. It is very simple and not difficult. There are several problems that need to be paid attention to, which are not highlighted in the official documents at present. You will definitely encounter them in the process of operation (AFTER all, I have encountered them).
Can see in the picture above I marked in red have three places in particular, the second is the special note, the official document just tell you execute the following command in the CMD can get the encrypted SHA1 value, but it says is the Debug version of the gm, according to the tutorial, you will get the following “development board SHA1” value, In time after you complete the release of the code, Baidu map in the loading use will appear to load out, unable to display and other problems.
The official application release SHA1 address: lbsyun.baidu.com/index.php?t…
Enter the command line and password to obtain information such as SHA1.
The official presentation in three ways, very comprehensive, but it did not explain to everyone in this part will encounter problems, there is no difference between the development version and the release version, the current SHA1 obtained according to the tutorial is the development version, did not say the release version.
Run the following command: keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey
Here we use CMD to demonstrate how to get SHA1 values for development and release versions.
- Run into the console
Windows: Run -> enter CMD -> OK.
Mac: Directly open the terminal.
- In the console, navigate to the. Android folder and type cd.android
The operations on Windows and Mac are the same. The following screenshot shows the Win effect.
To get the value of SHA1, run the following code in this folder.
keytool -list -v -keystore ~/.android/debug.keystore -alias android debugkey
Copy the code
The password used in the operation is the original android password. The developer can enter the password based on the actual situation.
As you can see in the image below, this is the SHA1 value that I obtained. In fact, this is the development version value, which can be written to the development version above.
Due to updates in Android Studio, we currently distribute software using a new key or our own defined key, which ends in.jks. If we want to produce SHA1 values for distribution, we need to locate the new key in CMD and use the new key to produce SHA1 values.
At this time, the release version and development version key, and PackageName will be filled in the need to fill in the above place to successfully complete baidu Map key application. Later, you can access the map normally only when you write it into the Android project.
Here we have completed the registration of Baidu map. Congratulations. You got your first shot off. Next I will show you how to download the SDK and add it to the project and successfully display baidu Map. Let’s look forward to the next tweet. Be there or be square.
Small remarks
Life is short, I don’t want to go after what I can’t see, I just want to catch what I can see.
Original is not easy, give a attention.
I am Hui, thank you for reading, if it is helpful to you, please like, forwarding thank you.