sdkinitializer.initialize (Getapplicationcontext ()); Setcontentview (R.LAYOUT.ACTIVITY_MAP); //Get map Control ReferenceMmapview =(Mapview) Findviewbyid (R.id.bmapview); Mbaidumap=Mmapview.getmap (); //sets whether to display a scale bar controlMmapview.showscalecontrol (false); //sets whether the zoom control is displayedMmapview.showzoomcontrols (false); //Delete Baidu Map logoMmapview.removeviewat (1); //Setting the marker iconBitmap =Bitmapdescriptorfactory.fromresource (R.drawable.maker); Mbaidumap.setonmapclicklistener (NewOnmapclicklistener () {@Override Public BooleanOnmappoiclick (Mappoi arg0) {//TODO auto-generated Method Stub return false; } //This method is to click on the map to listen@Override Public voidOnmapclick (latlng latlng) {//get latitude and longitude DoubleLatitude =Latlng.latitude; DoubleLongitude =Latlng.longitude; System.out.println ("Latitude=" + Latitude + ", longitude=" +longitude); //Clear Layer Firstmbaidumap.clear (); //defining maker coordinate pointsLATLNG point =Newlatlng (latitude, longitude); //build markeroption to add marker on the mapMarkeroptions options =Newmarkeroptions (). Position (point). icon (bitmap); //add marker on the map and showmbaidumap.addoverlay (options); //instantiate a geocoded query objectGeoCoder GeoCoder =geocoder.newinstance (); //set the inverse geocoding location coordinatesReversegeocodeoption op =Newreversegeocodeoption (); Op.location (LATLNG); //initiate an anti-geocoding request (latitude-longitude, address information)Geocoder.reversegeocode (OP); Geocoder.setongetgeocoderesultlistener (NewOngetgeocoderresultlistener () {@Override Public voidOngetreversegeocoderesult (Reversegeocoderesult arg0) {//get the coordinates of the clicked addressAddress =arg0.getaddress (); System.out.println ("Address=" +address);
/**
* Add text to the map
*/
Define the coordinate points that the text displays
LATLNG Lltext = new Latlng (latitude, longitude);
Build a Text Option object to add text to the map
Overlayoptions textoption = new Textoptions ()
. BgColor (0XAAFFFF00)
. FontSize (16)
. FontColor (Color.Black)
. Text (ADDRSTR)
. Rotate (-30)
. position (Lltext);
Adds the text object to the map and displays
Mbaidumap.addoverlay (textoption);
} @Override Public voidOngetgeocoderesult (Geocoderesult arg0) {}}); } }); } @Overrideprotected voidOnDestroy () {Super. OnDestroy ();//Implement Mmapview.ondestroy () when activity executes OnDestroy to achieve map life cycle management Mmapview.ondestroy ();} @Overrideprotected voidOnresume () {Super. Onresume ();//perform mmapview. Onresume () When activity executes Onresume, enabling map Lifecycle management mmapview.onresume ();} @Overrideprotected voidOnPause () {Super. OnPause ();//perform mmapview. OnPause () When activity executes OnPause, enabling map Lifecycle management mmapview.onpause ();}
Android Baidu Map Development Implementation Click on the map to add marker and get address information