First look at the effect you want to achieve
The first step,
Download SDK, basic configuration, Baidu development documentation very detailed, directly attached link http://lbsyun.baidu.com/index.php?title=androidsdk/guide/create-project/androidstudio
Step Two
On the Baidu developer platform to register and get key, fill SHA1 error prone, set the address Http://lbsyun.baidu.com/index.php?title=androidsdk/guide/create-project/ak
Question 1
When this problem occurs, do not panic, normal, it must be your key or SHA1 or package name did not write to, carefully control, the platform fill information, as well as the Androidmanifest file fill information.
Question 2
The problem is that you're not looking at the official documentation, the problem is that you didn't fill in the code in the app's Build.gradle
Workaround:
Sourcesets { main { ' libs ' // Description So path is the Libs path, associated with all Map SDK's so file } }
Note the location of the node here, don't write wrong
The third step, then directly on the mainactivity code, the code has comments, it is easy to understand
/*** Shop Details Show when viewing the map*/ Public classShopdetailsmapextendsbaseactivity {PrivateMapview Mmapview =NULL; PrivateBaidumap Mbaidumap =NULL; PrivateBitmapdescriptor Bitmapdescriptor; PrivateImageView Iv_map_return; @Overrideprotected voidonCreate (@Nullable Bundle savedinstancestate) {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.SHOP_DETAILS_MAP); Iv_map_return=(ImageView) Findviewbyid (R.id.iv_map_return); Iv_map_return.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (view view) {finish (); } }); /*Display Information*/ //layout in the InfowindowTextView TV =NewTextView (Shopdetailsmap. This); Tv.setbackgroundresource (R.MIPMAP.MAPTEXTBG); Tv.setpadding (20, 10, 20, 20); Tv.settextcolor (Android.graphics.Color.WHITE); Tv.settext ("Shop name" + "\ n" + "near Beijing South railway station"); Tv.setgravity (Gravity.center); Bitmapdescriptor=Bitmapdescriptorfactory.fromview (TV); //The display infowindow,-47 is an offset that offsets the infowindow upward and does not block marker//Get map Control ReferenceMmapview =(Mapview) Findviewbyid (R.id.bmapview); LATLNG Lltext=NewLATLNG (39.86923, 116.397428); Infowindow Infowindow=NewInfowindow (Bitmapdescriptor, Lltext,-47,NULL); //adds the text object to the map and displays//Get Map Control reference * /Mmapview =(Mapview) Findviewbyid (R.id.bmapview); Mbaidumap=Mmapview.getmap (); Mbaidumap.showinfowindow (Infowindow); /*here is the key to explain the floating-point variable behind the Zoomby you know Baidu map a total of {"10 meters", "20 meters", "50 meters", "100 meters", "200 meters", "500 meters", "1-kilometer", "2-kilometer", "5-kilometer", "10 Km "," 20-kilometer "," 25-kilometer "," 50-kilometer "," 100-kilometer "," 200-kilometer "," 500-kilometer "," 1000-kilometer "," 2000-kilometer "}*/mapstatusupdate mapstatusupdate= Mapstatusupdatefactory.zoomby (3); Mbaidumap.setmapstatus (MAPSTATUSUPDATEFACTORY.NEWLATLNG (Lltext));//set the location of the position in the middle of the screenMbaidumap.animatemapstatus (mapstatusupdate);//mbaidumap.addoverlay (option);//Mbaidumap.addoverlay (textoption);} @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 (); }}
After writing these, you can achieve the effect, if you do not understand, you can send me a message, email [email protected]
Android integrated Baidu map detailed steps and error issues