Before, I always wanted to study the integration and use of maps, but I had no face because of my real computer and I didn’t have too much free time. I studied it in the previous stage, and I will summarize it today. Cut short the gossip and get to the point. ### Step 1: Get the secret key
- 1, Baidu —- input “Baidu map API”
- 2. Log in to your Baidu account and choose development –Android Map SDK — to obtain the secret key. See the following figure for details
If the above is configured, one will be displayed at this time
- 3, this time we go to download the SDK, (or development -Android map SDK- related download – can customize, can also be a download), download a good SDK decompression as follows (I this is a custom, may have to write jar package is not the same, but does not affect)
- 4. Next we start to add jar packages and.so libraries to our application.
- 5. Let’s look at the configuration in the AndroidMainfest.xml file.
- 1> Required permissions
** <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_SETTINGS"/>**
- 1> Required permissions
- 2> put in the
<meta-data
android:name="com.baidu.lbsapi.API_KEY"
android:value="The secret key you requested."/>
Copy the code
At this point, the integration work is basically completed, let’s start our Hello Baidu_Map. ###Hello Baidu_Map: myApplication.java: myApplication.java:
package com.example.mylocation;
import android.app.Application;
import com.baidu.mapapi.SDKInitializer;
/**
* Created by wuyinlei on 2016/3/1.
*/
public class MyApplication extends Application{
@Override
public void onCreate() { super.onCreate(); / / initialize SDKInitializer. The initialize (getApplicationContext ()); }}Copy the code
MainActivity.java:
package com.example.mylocation;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.baidu.mapapi.map.MapView;
public class MainActivity extends AppCompatActivity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapView);
}
protected void onDestroy() { super.onDestroy(); // Execute mmapView.ondestroy () when the activity executes onDestroy, and implement mapView.ondestroy (); } @Override protected voidonResume() { super.onResume(); // Execute mmapView.onresume () when the activity executes onResume to implement the map lifecycle management mapView.onresume (); } @Override protected voidonPause() { super.onPause(); // Execute mmapView.onpause () when the activity is executing onPause to implement the map lifecycle management mapView.onpause (); }}Copy the code
activity_main.xml:
<? xml version="1.0" encoding="utf-8"? > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mylocation.MainActivity">
<com.baidu.mapapi.map.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"></com.baidu.mapapi.map.MapView>
</LinearLayout>
Copy the code
This time to run, see the reality of the effect, and the official whether the same.

Okay, so that’s it for this one, and then there are other ones that I’m going to wrap up today.