Android Baidu map Add Marker by cropping a picture

Source: Internet
Author: User

Initialize Baidu Map:

1 Private void initviews () {24         mmapview = (Mapview) Findviewbyid (R.id.bmapview); 5         Mbaidumap = mmapview.getmap (); 6         // Initialize map extent levels 7         Mapstatusupdate MSU = Mapstatusupdatefactory.zoomto (14.0f); 8         Mbaidumap.setmapstatus (MSU); 9     }

--------------------Ornate Split Line-----------------------

// Initialize bitmap information, recycle in time when not in use Bitmapdescriptor friend_1;

Initialize the cropped picture (here for a circular image):

1 friend_1 = bitmapdescriptorfactory.frombitmap (2                     bmaputil.createcircleimage ( Bitmapfactory.decoderesource (Getresources (), r.drawable.friend_1), 90));

Circular image Generation Method:

1 /**2 * Draw Circular pictures based on original and variable length3      * @paramSource4      * @parammin5      * @return6      */7      Public StaticBitmap Createcircleimage (Bitmap source,intradius) {8 Bitmap scaledsrcbmp;9         intdiameter = radius * 2;Ten         //In order to prevent the width of the height is not equal, resulting in a circular picture deformation, so the rectangle in the middle of the largest square picture One         intBmpwidth =source.getwidth (); A         intBmpheight =source.getheight (); -         intSquarewidth = 0, squareheight = 0; -         intx = 0, y = 0; the Bitmap Squarebitmap; -         if(Bmpheight > Bmpwidth) {//taller than wide -Squarewidth = Squareheight =Bmpwidth; -x = 0; +y = (bmpheight-bmpwidth)/2; -             //capturing a square image +Squarebitmap =Bitmap.createbitmap (source, x, Y, Squarewidth, A squareheight); at}Else if(Bmpheight < Bmpwidth) {//large to High -Squarewidth = Squareheight =Bmpheight; -x = (bmpwidth-bmpheight)/2; -y = 0; -Squarebitmap =Bitmap.createbitmap (source, x, Y, Squarewidth, - squareheight); in}Else { -Squarebitmap =Source; to         } +         if(Squarebitmap.getwidth ()! =diameter -|| Squarebitmap.getheight ()! =diameter) { theScaledsrcbmp =bitmap.createscaledbitmap (squarebitmap, diameter, *Diametertrue); $}Else {Panax NotoginsengScaledsrcbmp =Squarebitmap; -         } theBitmap output =Bitmap.createbitmap (Scaledsrcbmp.getwidth (), + scaledsrcbmp.getheight (), config.argb_8888); ACanvas Canvas =NewCanvas (output); the  +Paint paint =NewPaint (); -Rect rect =NewRect (0, 0, Scaledsrcbmp.getwidth (), $ scaledsrcbmp.getheight ()); $  -Paint.setantialias (true); -Paint.setfilterbitmap (true); thePaint.setdither (true); -Canvas.drawargb (0, 0, 0, 0);WuyiCanvas.drawcircle (Scaledsrcbmp.getwidth ()/2, theScaledsrcbmp.getheight ()/2, Scaledsrcbmp.getwidth ()/2, - paint); WuPaint.setxfermode (NewPorterduffxfermode (mode.src_in)); - Canvas.drawbitmap (scaledsrcbmp, rect, rect, paint); AboutBMP =NULL; $Squarebitmap =NULL; -Scaledsrcbmp =NULL; -         returnoutput; -}

Initialize location information:

1 New LATLNG (39.963175, 116.400244);

Initialize Overlayoptions:

1 New markeroptions (). Position (position_1). Icon (friend_1) 2                 . ZIndex (9). draggable (true);

Then add to the map via Addoverlay:

1 mmarkera = (Marker) (Mbaidumap.addoverlay (OoA));

Registration Setonmarkerclicklistener:

Mbaidumap.setonmarkerclicklistener (new  Onmarkerclicklistener () {            public  Boolean Onmarkerclick (final  Marker Marker) {       //  todo to determine Mmarkera click events       }}

When exiting, release the resource:

@Overrideprotected voidOnPause () {//Mapview life cycle is synchronized with activity, call Mapview.onpause () when activity hangsMmapview.onpause (); Super. OnPause (); } @Overrideprotected voidOnresume () {//the life cycle of the Mapview is synchronized with the activity and needs to be called mapview.onresume () when activity resumesMmapview.onresume (); Super. Onresume (); } @Overrideprotected voidOnDestroy () {//the life cycle of the Mapview is synchronized with the activity and needs to be called Mapview.destroy () when the activity is destroyedMmapview.ondestroy (); Super. OnDestroy (); //Reclaim Bitmap Resourcesfriend_1.recycle (); }

Android Baidu map Add Marker by cropping a picture

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.