The final effect is as follows:
This needs to be detailed, the preparation work is more cumbersome.
The first step: go to Baidu to apply for a developer account, create a new Android app, will let you enter the developer SHA1, currently I only get the development version of SHA1, the release version there is also filled with this.
Get methods such as:
Under C:\Users\Administrator\.android, call out the command line and enter
Keytool-list-v-keystore Debug.keystore, will get three kinds of fingerprint certificate, choose the SHA1 type of certificate (key password is Android)
Red Line Place is, fill in the Adroid SDK application interface, will get an AK code, copy down.
Step Two: Create a new Android project with AS, add AK Code and permissions in the Androidmanifest.xml file
(1) Add a development key in application
<application> <meta-data android:name= "Com.baidu.lbsapi.API_KEY" android:value= "AK KEY"/ > </application>
2) Add the 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.GET_TASKS "/><uses-permission android: Name= "Android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name= "Android.permission.WRITE _settings "/>
Step three: Introduce the JAR package
In Http://lbsyun.baidu.com/index.php?title=androidsdk/sdkandev-download click on a button to download, go to
Copy all of the 7 jar packages below into the Lib directory under the project directory:
Then create a new Jnilibs folder under the source code directory and copy the remaining folders:
Fourth step: Add Mapview to the main layout file:
<com.baidu.mapapi.map.
Texturemapview
Android:id= "@+id/bmapview"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
Android:clickable= "true"/>
Special attention is paid to the highlighted part.
In the layout background code, add:
Package Com.example.baidumapdemo;import Android.support.v7.app.appcompatactivity;import android.os.Bundle; Import Com.baidu.mapapi.sdkinitializer;import Com.baidu.mapapi.map.mapview;import Com.baidu.mapapi.map.TextureMapView; Public classMainactivity extends Appcompatactivity {texturemapview Mmapview=NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {//super.oncreate (savedinstancestate); //Setcontentview (r.layout.activity_main);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); //Get map Control ReferenceMmapview =(Texturemapview) Findviewbyid (R.id.bmapview); } @Overrideprotected voidOnDestroy () {Super.ondestroy (); //Implement Mmapview.ondestroy () when activity executes OnDestroy to achieve map life cycle managementMmapview.ondestroy (); } @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 (); }}View Code
Full Source code Download
Baidu Map Development under Android (a): Basic map display