Get the Security Code
Security code composition rules: Android signature certificate sha1 value + packagename For example:
The SHA1: BB: 0D: the AC: 74: D3: 21: the E1: 43: 67: 71: 9B: 62: 91: the AF: the A1: 66: 6E: 44: 5D: 75
Package name: com.baidumap.demo
After entering the security code, click “OK” to complete the configuration of the application, you will get a created Key, please keep your application Key. At this point you can use the new Key to complete your development work.
Project Configuration Method
Step 1:
In the project app / libs directory into baidumapapi_vX_X_X.jar package, in the src / main / directory new jniLibs directory, the project will automatically load the src directory so dynamic library, put libBaiduMapSDK_vX_X_X_X.so as shown below , Note that the first three versions of jar and so must be the same, and to ensure that the use of a download folder in the two files, not different functional components of the jar or so cross-use.
So the configuration can also refer to the directory structure given demo, as shown below, in the app project path, the new libs, and in the libs directory into the corresponding different CPU architecture so the file. So the project does not automatically load the libs under so, need to compile the gradle, by adding the code: jniLibs.srcDir ‘libs’ to explain the path of the libs path.
Step 2:
Project configuration also need to integrate the jar package to their own projects, as shown in the figure above, into the libs directory. For each jar file, right – select Add As Library, into the project. Corresponding to the build.gradle generated project depends on the jar file description, as shown:
Jar configuration can also refer to eclipse method, the following operations:
Select File -> Project Structure from the menu bar.
In the Project Structure dialog box that pops up, select module, and then click the Dependencies tab.
Click on the green plus select File dependency. Then select the jar package to add to complete the above operation in the app directory under the build.gradle file, there will be the introduction of the class library, as shown above.
Show Baidu Map
Baidu map SDK for developers to provide a convenient interface to display Baidu map data, in the following steps, you can use in your application Baidu map data:
The first step: create and configure the project (see the specific methods of the project configuration section);
The second step: AndroidManifest add development key, the required permissions and other information;
- In the application to add development key
<application > < Meta - Data Android : name = "com.baidu.lbsapi.API_KEY" Android : value The = "Developer Key" /> </application >
- Add the required permissions
< uses - permission Android : name = "android.permission.ACCESS_NETWORK_STATE" /> < uses - permission Android: name = "android.permission.INTERNET android.permission.ACCESS_NETWORK_STATE" /> < uses - permission Android : name = "com.android.launcher.permission .READ_SETTINGS " /> < uses - permission Android: name = " android.permission.WRI " /> < uses - permission Android : name = " android.permission.CHANGE_WIFI_STATE " /> < uses - permission Android : name = " Android. permission.ACCESS_WIFI_STATE " /> < uses - permission Android: name = " android.permission.GET_TASKS " /> < uses - permission Android : name = " android.permission.WRITE_EXTERNAL_STORAGE " /> < uses - permission Android: name = " Android .permission.WRITE_SETTINGS " />
The third step, in the layout of the xml file to add the map control;
< com. Baidu . Mapapi . Map . MapView Android : id = "@ + id / bmapView" Android : layout_width = "fill_parent" Android : layout_height = "fill_parent" Android : clickable = "true" />
The fourth step is to initialize the Context global variable that the SDK refers to when the application is created:
public class MainActivity extends Activity { @Override protected void onCreate ( Bundle savedInstanceState ) { Super onCreate ( savedInstanceState ) ; // Before using the SDK each component initialization context information, passing the ApplicationContext // Note that this method again setContentView way to achieve before SDKInitializer. initialize ( getApplicationContext ( ) ) ; setContentView ( R. layout . activity_main ) ; } }
Note: need to call before using the SDK various functional components
SDKInitializer.initialize (getApplicationContext ()) ;, so we recommend that the method on the Application of the initialization methodThe fifth step, create a map Activity, manage the map life cycle;
public class MainActivity extends Activity { MapView mMapView = null ; @Override protected void onCreate ( Bundle savedInstanceState ) { Super . onCreate ( savedInstanceState ) ; // Before using the SDK each component initialization context information, passing the ApplicationContext // Note that this method again setContentView way to achieve before SDKInitializer. initialize ( getApplicationContext ( ) ) ; setContentView ( R. layout . activity_main ) ; // Get a reference to the map control mMapView = ( MapView ) findViewById ( R. above mentioned id . bmapView ) ; } @Override protected void onDestroy ( ) { Super . onDestroy ( ) ; // executed when the activity execution onDestroy mMapView.onDestroy (), to achieve the map lifecycle management mMapView. onDestroy ( ) ; } @Override protected void onResume ( ) { Super . onResume ( ) ; // executed when the activity execution onResume mMapView onResume (), map to achieve life-cycle management. mMapView. onResume ( ) ; } @Override protected void onPause ( ) { Super . onPause ( ) ; // executed when the activity execution onPause mMapView onPause (), map to achieve life-cycle management. mMapView. onPause ( ) ; } }
After completing the above steps, run the program to display the following map in your application.