Example of a custom markers Android Gold Map

Source: Internet
Author: User

Before the blog said the map embedding and positioning, today to say on the map to show some of what we want. There is a markers (tag) on the map, but it only shows an oval icon, which is generally not in line with our needs, so we need to customize it. First tag has some of the following attributes;

1.position (Required) marks the latitude and longitude value of the position on the map. parameter cannot be empty.

2.title a string displayed on the information window when the user clicks on the tag.

3.snippet additional text, shown below the title.

4.draggable If you allow the user to move the tag freely, set to "true". By default, is "false."

5.visible set "false" and the tag is not visible. By default, is true.

6.anchor icons are placed on the map datum points. By default, the anchor point is the middle of the bottom edge of the picture.

7.perspective to set true, the tag has a near-large, far-small effect. False by default.

8. The Marker.setrotateangle () method can be used to set the rotation angle of the marker, starting from north and counterclockwise. If set to rotate 90 degrees, Marker.setrotateangle (90)

9. Use the Setflat () method to set whether the flag is displayed

Custom icons are usually set by Bitmapdescriptor. We can use one of the following method definitions in the class bitmapdescriptorfactory.

1.fromAsset (String Assetname) uses images to create custom tags in the assets directory.

2.fromBitmap (Bitmap image) creates a custom tag using a bitmap image.

3.fromFile (String path) creates a custom icon for the file that specifies the path.

4.fromResource (int ResourceID) creates a custom icon using a resource that already exists.

Let's take a look at the effect you want to achieve:

map with Tag Implementation Effect


The idea is to customize the layout, get the data to fill in the appropriate location, then turn view into bitmap and invoke the Amap.addmarker (Markeroptions) method to add to the map.

    1. To customize the layout and populate the data:

for  (Int i = 0; i < positioneneitylist.size ();  i++)  {     if  (Positioneneitylist.get (i). GetType (). Equals ("1"))  {    

   view view = view.inflate (Getactivity (), r.layout.view_day, null);        TextView tv_price =  (TextView)  view.findviewbyid

(R.id.tv_price);        TextView tv_price_status =  (TextView)  

View.findviewbyid (R.id.tv_price_status);

       tv_price.settext (Positioneneitylist.get (i). GetPrice ());

       tv_price_status.settext ("Yuan/Time");        bitmap bitmap = commentactivity.convertviewtobitmap (

view);        drawmarkeronmap (NEW&NBSP;LATLNG (double.parsedouble) ( Positioneneitylist.get (i). Getlatitude ()),  double.parsedouble (Positioneneitylist.get (i) getlongitude ()), bitmap, 

Positioneneitylist.get (i). GetId ());     }  }


2. Turn into bitmap:

View turn Bitmap public

static Bitmap convertviewtobitmap (view view) {

view.measure ( View.MeasureSpec.makeMeasureSpec (0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec (0,    View.MeasureSpec.UNSPECIFIED));

View.layout (0, 0, view.getmeasuredwidth (), View.getmeasuredheight ());

View.builddrawingcache ();

Bitmap Bitmap = View.getdrawingcache ();

return bitmap;

}

3. Add to map:

/**  *  map marker  *  *  @param  point       Marker coordinate point position (example:latlng point = new latlng 39.963175,  *    

               116.400244); )  *  @param  markerIcon  icon  *  @return  marker Object  */private marker  Drawmarkeronmap (latlng point, bitmap markericon, string id)  {     if  (amap != null && point != null)  {         marker marker = amap.addmarker (New MarkerOptions (). Anchor ( 0.5f, 1)                  Position (point)                  .titLe (ID)                 .icon (

Bitmapdescriptorfactory.frombitmap (Markericon)));

          return marker;

    }     return null;  }


, which makes the above effect happen.

Related Article

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.