Here's an example of a custom markers for Android gold maps, and hopefully this article will give you an idea of how to customize the markers for Android gold maps.
The previous blog said the map embedding and positioning, today to say on the map to show some of what we want. There is a self-contained markers (marker) in the map, but it only shows an ellipse icon, which is generally not in line with our needs, so we need to customize it ourselves. The following attributes are marked first;
1.position (Required) marks the latitude and longitude values of the position on the map. The parameter cannot be empty.
2.title when the user clicks on the tag, the string displayed on the Info window.
3.snippet additional text, shown below the title.
4.draggable If you allow the user to freely move the tag, set to "true". The default is "false".
5.visible set "false", the tag is not visible. By default, "true".
The 6.anchor icon is placed at the Datum point on the map. By default, the anchor point is from the middle of the bottom edge of the picture.
7.perspective is set to true, and the marker has a nearly large far small effect. False by default.
8. The rotation angle of the marker can be set by the Marker.setrotateangle () method, starting from True north and counting counterclockwise. If set to rotate 90 degrees, Marker.setrotateangle (90)
9. Use the Setflat () method to set whether the flag is affixed to the display
Custom icons are usually set by Bitmapdescriptor. We can use one of the following method definitions in class Bitmapdescriptorfactory.
1.fromAsset (String assetname) creates a custom tag in the assets directory using an image.
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 with a resource that already exists. first look at the effect you want to achieve:
Map with self-tagging implementation effect
The idea is to customize the layout, get the data to fill in the appropriate location, and then turn the view into bitmap, and call the Amap.addmarker (Markeroptions) method to add to the map.
-
To customize the layout and populate the data:
for(inti =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 (NewLATLNG (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 (00, view.getmeasuredwidth (), View.getmeasuredheight ()); View.builddrawingcache (); = View.getdrawingcache (); return bitmap;}
3. Add to the map:
/** * draw marker on a map * * @param point marker coordinates (example:latlng points = new LATLNG (39.963175, * 116 .400244); ) * @param markericon icon * @return Marker Object*/PrivateMarker Drawmarkeronmap (latlng point, Bitmap Markericon, String id) {if(AMap! =NULL&& Point! =NULL) {Marker Marker= Amap.addmarker (NewMarkeroptions (). Anchor (0.5f,1). Position (point). title (ID). Icon (Bitmapdescriptorfactory.frombitmap (MA (Rkericon))); returnmarker; } return NULL; }
This achieves the above effect.
Android Gold Map Custom Markers Example