Android import Baidu Map SDK detailed steps

Source: Internet
Author: User
Tags sha1

Today to pay everyone how to access the SDK Baidu map, the steps in fact and Baidu official online development guidelines, write down to do a summary.

1. Register the Baidu developer account, directly to the official website registration on the line, if not registered, you can obtain the secret key when the system will remind you to register. Baidu's lbs home site is:

Http://developer.baidu.com/map/index.php?title=%E9%A6%96%E9%A1%B5


2. With the Baidu developer account can go to apply for the development of the app, because Baidu SDK needs and app binding, in the creation of the app need to provide Android key and package name, can refer to the link:

Http://developer.baidu.com/map/index.php?title=androidsdk/guide/key

(1) Create an app page:

(2) Security Code Access: (Above the Baidu link inside there, I used here is the Eclipse method)

Select the Red box area (the Red box area is the value of SHA1), Android, Build, window, preferences

The security code that needs to be filled in is: SHA1 key + ";" + Package name

SHA1 secret key:

Package Name:


Then make sure you can generate the APK: (The red box in the picture is the next step we need to configure the key to register the app

3. Download Baidu Map SDK:

Http://developer.baidu.com/map/index.php?title=androidsdk/sdkandev-download

After the download, the following three packages are available: Instance of Lib Library, document--

Then unzip the Lib library to get the jar packages and so files we want:


4. Introduction of Baidu Map in the project:

1. To create a project, note here that we should have already registered the project before applying for the app, the app and SDK should be well-bound, so here we use the previously registered project. My project is called Mapdemo.

2. Create the libs/folder under the project folder, if you created the project with Eclipse, you should already have it.

Here are two steps: (1) Copy the Baidumapapixxxxxx.jar to the root directory of the libs/, (2) Create a folder armeabi/directory under lib/and copy the libbaidumapxxx.so. When you are done



3. Right-click Properties, Java Build Path, Libraries, add External Jars, select the jar package file under the hard disk directory, and then introduce


4. After the introduction of the package, we can use the Baidu SDK to develop:

Here, first, put an official document address: Http://developer.baidu.com/map/index.php?title=androidsdk/guide/hellobaidumap

(1) First add in the Androidmainefest.xml file:

<1> add under the Application tab:

<meta-data
Android:name= "Com.baidu.lbsapi.API_KEY"
Android:value= "AK value generated when app was just applied"/>


<2> Add Permissions:

<uses-permission android:name= "Android.permission.GET_ACCOUNTS"/>
<uses-permission android:name= "Android.permission.USE_CREDENTIALS"/>
<uses-permission android:name= "Android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name= "Android.permission.AUTHENTICATE_ACCOUNTS"/>
<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.CHANGE_WIFI_STATE"/>
<uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name= "Android.permission.BROADCAST_STICKY"/>
<uses-permission android:name= "Android.permission.WRITE_SETTINGS"/>
<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>

Figure:


(2) Modify layout configuration file, introduce Baidu map control:

    <com.baidu.mapapi.map.mapview        android:id= "@+id/bmapview"        android:layout_width= "Fill_parent        " android:layout_height= "Fill_parent"        android:clickable= "true"/>

(3) Modify Mainactivity.java

Package Com.example.baidumapdemo;import Com.baidu.mapapi.sdkinitializer;import Com.baidu.mapapi.map.MapView; Import Android.os.bundle;import Android.app.activity;import Android.view.menu;public class MainActivity extends Activity {Mapview Mmapview = null, @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( savedinstancestate);//Initialize the context information before using each component of the SDK and pass in the applicationcontext// Note that this method is to be implemented before Setcontentview method Sdkinitializer.initialize (Getapplicationcontext ()); Setcontentview (r.layout.activity _main); Mmapview = (Mapview) Findviewbyid (R.id.bmapview);} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}  @Overrideprotected void OnDestroy () {Super.ondestroy (); Mmapview.ondestroy (); } @Overrideprotected void Onresume () {super.onresume (); Mmapview.onresume ();} @Overrideprotected void OnPause () {super.onpause (); Mmapview.onpause ();}}

The code should be simple, initialize the library, and invoke the life cycle of the mapview in the activity lifecycle, so that's it:
Sdkinitializer.initialize (Getapplicationcontext ());


5. Run the app: ( note here do not run on the simulator, will not load the SDK library errors, directly on the real machine running on the OK), run the result:


OK, done, end.

Android import Baidu Map SDK detailed steps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.