First, inherit the abstract class itemizedoverlay and override the ONTAP method.
Class myoveritem extends itemizedoverlay <overlayitem >{< br/> private list <overlayitem> geolist = new arraylist <overlayitem> (); <br/> private drawable marker; <br/> private context mcontext; <br/> // The Dead poi point is written here .. You can obtain from the Server Query </P> <p> private double mlat1 = 40.0506; // point1 latitude <br/> private double mlon1 = 116.288700; // point1 longitude <br/> private double mlat2 = 40.051723; <br/> private double mlon2 = 116.287741; <br/> private double mlat3 = 40.052723; <br/> private double mlon3 = 116.286741; <br/> Public myoveritem (drawable marker, context) {<br/> super (boundcenterbottom (Marker )); <br/> This. marker = marker; <br/> This. mcontext = context; </P> <p> // construct a geopoint with a given latitude and longitude, in the unit of (degree * 1e6) <br/> geopoint p1 = new geopoint (INT) (mlat1 * 1e6), (INT) (mlon1*1e6 )); <br/> geopoint P2 = new geopoint (INT) (mlat2 * 1e6), (INT) (mlon2*1e6 )); <br/> geopoint P3 = new geopoint (INT) (mlat3 * 1e6), (INT) (mlon3*1e6 )); <br/> // the three parameters used to construct an overlayitem are: the position of the item, the title text, and the text fragment. <br/> geolist. add (New overlayitem (P1, "p1", "point1"); <br/> geolist. add (New overlayitem (P2, "p2", "point2"); <br/> geolist. add (New overlayitem (P3, "P3", "point3 ")); <br/> // This method is used to synchronize the current geolist overlay to the list in the parent class itemizedoverlay for re-painting. <br/> // when the geolist data changes you need to call this method <br/> populate (); </P> <p >}< br/> @ override <br/> Public void draw (canvas, mapview, Boolean shadow) {<br/> // projection interface is used for the transformation between the screen pixel coordinate system and the coordinate system of the earth's surface latitude and longitude Points <br/> projection = mapview. getprojection (); <br/> for (INT Index = size ()-1; index >=0; index --) {// traverse geolist <br/> overlayitem = getitem (INDEX); // obtain the item of the given index <br/> String title = overlayitem. gettitle (); <br/> // converts the longitude and latitude to the screen pixel coordinates relative to the upper left corner of the mapview. <br/> point = projection. topixels (overlayitem. getpoint (), null); <br/> paint paintcircle = new paint (); <br/> paintcircle. setcolor (color. red); <br/> canvas. drawcircle (point. x, point. y, 5, paintcircle); // circle <br/> paint painttext = new paint (); <br/> painttext. setcolor (color. black); <br/> painttext. settextsize (15); <br/> canvas. drawtext (title, point. x, point. y-25, painttext); // draw the text <br/>}< br/> super. draw (canvas, mapview, shadow); <br/> // adjust a drawable boundary so that (0, 0) is a pixel in the center of the last row at the bottom of the drawable <br/> boundcenterbottom (Marker ); <br/>}< br/> @ override <br/> protected overlayitem createitem (int I) {<br/> return geolist. get (I); <br/>}< br/> @ override <br/> Public int size () {<br/> return geolist. size (); <br/>}< br/> @ override <br/> // process the ontouch event of the click event <br/> // mapview will be propagated to the ontouch method of overlay by clicking the range can determine which overlay ONTAP is triggered. <br/> protected Boolean ONTAP (int I) {<br/> setfocus (geolist. get (I); <br/> toast. maketext (this. mcontext, geolist. get (I ). getsnippet (), <br/> toast. length_short ). show (); <br/> return true; <br/>}< br/>
In Google API, mapview can obtain the overlay list.
Private void initoverlayitem () {<br/> drawable marker = getresources (). getdrawable (R. drawable. poi_1); // obtain the resource to be marked on the map </P> <p> marker. setbounds (0, 0, marker. getintrinsicwidth (), marker <br/>. getintrinsicheight (); // defines the location and boundary for the maker </P> <p> mapview. getoverlays (). add (New myoveritem (Marker, this); // Add the itemizedoverlay instance to mmapview <br/>}
Mapview is repainted in the ondraw method in sequence.