Using the Baidu Map API for Android Map application development (ECLIPSE)

Source: Internet
Author: User
Tags sha1

With the rise of location-based services, the map-like app presents an outbreak trend. As the map provider opens up a lot of APIs. For developers to develop PC-or mobile-based applications.

Now we are researching the development of the Android project using the Baidu Map SDK.

This article discusses how to import Baidu Map SDK.

Mainly divided into server-side configuration and client configuration.

(1) First to have a Baidu account, account can go to Baidu website application, and then login: http://developer.baidu.com/map/index.php?

Title=%e9%a6%96%e9%a1%b5. Log in using your own account password. This site is Baidu to provide lbs Service site.


(2) Click "SDK Download" in Android development to download the SDK or demo for map development.

In the demo, Baidu provides us with a feature-rich sample of code demonstrations. You can download the required SDK based on your needs.


(3) After the download, there will be a number of jar packages and a Armabi directory, the jar package and the Armabi directory is copied to the Eclipseproject directory under the Libs directory.




(5) Eclipse opens Windows-->preferences-->android-->build and gets the SHA1 fingerprint value on the right: "3b:bf:6c:48:0b:ee:79.

。。。

”。 and record the package name of your application. As this article uses Com.example.mapdemo.

.


.


(6) to the Baidu Map API site just now, click on the upper right corner of the "API console", click "Create App", create a new app. Configuration parameters such as the following, the most critical security code is: SHA1; package name.

The middle is a semicolon in the English state. such as: 3b:bf:6c:48:0b:ee:79.

....; Com.example.mapdemo. App type select Android SDK. Click "Submit". This step is important. The fact that many maps cannot be displayed is due to a problem with this step. An app created on the server and a project in your eclipse one by one accordingly, note that it is not a one-to-many or many-to-one relationship. So the security code is very important.


(7) After submission, record access to the application AK, this is the API key. It will be used later in the code. As the key to access the server.


(8) The configuration on the server side of Baidu has been completed. Write the code below and add it in Androidmenifest.xml:

    <application//self-generated code        <meta-data            android:name= "Com.baidu.lbsapi.API_KEY"            android:value= " Join the above AK "/>    </application>

Join 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.GET_TASKS"/>    <uses-permission android:name= "Android.permission.WRITE _external_storage "/>    <uses-permission android:name=" Android.permission.WRITE_SETTINGS "/>

(9) Add a map control to the layout file:

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

(10) Add code to Mainactivity.java:

public class Mainactivity extends Activity {Mapview Mmapview = null;//The control used to display the map; @Overrideprotected void OnCreate (Bundle s Avedinstancestate) {super.oncreate (savedinstancestate); Sdkinitializer.initialize (Getapplicationcontext ());//Initialize the Map SDK, note must be written in Setcontentview (R.layout.activity_main); Code before; Setcontentview (r.layout.activity_main); Mmapview = (Mapview) Findviewbyid (R.id.bmapview);//bound control;}@ overrideprotected void OnDestroy () {//Manage the life cycle of the map: Destroy Super.ondestroy (); Mmapview.ondestroy ();} @Overrideprotected void Onresume () {//display; Super.onresume (); Mmapview.onresume ();} @Overrideprotected void OnPause () {//pause; Super.onpause (); Mmapview.onpause ();}}

(11) After writing a small amount of code, the execution of the program, the interface will be able to display the map, the project successfully imported Baidu Map SDK. With this foundation, you can develop more complex maps-based apps.


This article is a reference to Baidu Map development document: Http://developer.baidu.com/map/index.php?title=androidsdk/guide/hellobaidumap


Using the Baidu Map API for Android Map application development (ECLIPSE)

Related Article

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.