Simple use of the Baidu map developed by Android

Source: Internet
Author: User
Tags sha1

More and more applications to the positioning, navigation of these functions, in fact, the implementation of a Baidu map is also very simple, this blog will teach you a simple implementation of a Baidu map. Take a look:

The first step: to use Baidu Map, must have Baidu map key, to get this key, you need to provide two information: SHA1 and the application of the package name.

* Get SHA1:

Open your Android adb directory, typically in the C-drive user directory with. Android as the file name.

This debug file is the file that gets the SHA1 value. Next win+r, enter CMD. Come to the Command Window interface: Enter the CD first. Android comes in this folder and then enters Keytool-list-v-keystore debug.keystore

Prompts you to enter the password, the default is Android. Because it is the command window to enter the password does not show the number of inputs, enter a good return, you can see our SHA1 value.

* * To get the package name, copy the package name in our Android configuration file:

With these two values you can apply to the key.

The second step is to integrate the Baidu SDK into your project.

Put the SDK down and you can see these files:

The last one is the jar file, which can be imported into the library with one click and other for different phone architectures. So file. Test your jar file into the Libs directory and right-click Add as Laribary. Next, under the main file, create a new Jnilibs folder and test the remaining files inside.

The third part, configure the relevant data.

* Now configure a global parameter in the configuration manifest file:

The second parameter is your key. This is not to be seen here.

* * in the layout:

<com.baidu.mapapi.map.TextureMapView        android:layout_width= "Match_parent"        android: Layout_height= "Match_parent"        android:id= "@+id/bmapview"        android:clickable= "true "></com.baidu.mapapi.map.TextureMapView>

In the activity:

 Super. OnCreate (savedinstancestate); //initializes the context information before using each component of the SDK, passing in the ApplicationContext//Note that this method should be implemented before setcontentview the methodsdkinitializer.initialize (Getapplicationcontext ());        Setcontentview (R.layout.activity_main); Mmapview=(Texturemapview) Findviewbyid (R.id.bmapview); Baidumap=Mmapview.getmap (); MSU= MAPSTATUSUPDATEFACTORY.NEWLATLNG (NewLATLNG (30.5715920000,104.2077620000)); Baidumap.setmapstatus (MSU);} @Overrideprotected voidOnDestroy () {Super. OnDestroy (); //Implement Mmapview.ondestroy () when activity executes OnDestroy to achieve map life cycle managementMmapview.ondestroy ();    Unregisterreceiver (Broadcastreceiver); } @Overrideprotected voidOnresume () {Super. Onresume (); //perform mmapview. Onresume () When activity executes Onresume, enabling map Lifecycle managementMmapview.onresume (); } @Overrideprotected voidOnPause () {Super. OnPause (); //perform mmapview. OnPause () When activity executes OnPause, enabling map Lifecycle managementMmapview.onpause (); }

Note that the view's life cycle is consistent with the activity's life cycle. sdkinitializer.initialize (Getapplicationcontext ()); This method should be written before the layout. It is recommended to initialize it in the OnCreate () method of your application class. I am here to locate the coordinates in my school. OK, a simple Baidu map is realized, here first open. Next, I will introduce some important uses of Baidu map, if you think I write a good, can recommend a wave Oh ~

Simple use of the Baidu map developed by Android

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.