Android Baidu Map Development Implementation Click on the map to add marker and get address information

Source: Internet
Author: User

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

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.