Here is an example that draws a point at the current center of the
map. Move the map and you get another point with a line in between.
You can see the result here:
http://android-schweiz.blogspot.com/

 Be careful, I am in the middle of writing the code,it's ugly but it
does work.
As you can see, there is indeed an ontab method and i really do use
getProjection, as i want to do some custom drawing.
If you just want to set a marker, there are easier ways. Google for
any tutorial on that topic .-)

Greetings from Berne,
Stephan


@SuppressWarnings("unchecked")
public class TrackingOverlay extends ItemizedOverlay {
        Context mContext;
        private ArrayList<OverlayItem> overlays = new
ArrayList<OverlayItem>();
        private ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();
        public static final String TAG = ShowMap.TAG;
        private static Paint linePaint;
        public static String dateString = "Date";

        public TrackingOverlay(Drawable defaultMarker) {
                super(boundCenterBottom(defaultMarker));
                linePaint = new Paint();
                linePaint.setColor(Color.GREEN);
                linePaint.setStrokeWidth(10);
                linePaint.setDither(true);
                linePaint.setStyle(Style.FILL);
                linePaint.setAntiAlias(true);
                linePaint.setStrokeJoin(Paint.Join.ROUND);
                linePaint.setStrokeCap(Paint.Cap.ROUND);
                populate();
        }

        public void addOverlay(OverlayItem overlay) {
                overlays.add(overlay);
                setLastFocusedIndex(-1);
                // Each time we add a new OverlayItem, we must call populate(),
which
                // will read each of out OverlayItems and prepare them to be 
drawn.
                populate();
        }

        public void addItem(GeoPoint p) {
                Calendar cal = Calendar.getInstance();
                DateFormat formatter = new SimpleDateFormat();
                String date = formatter.format(cal.getTime()); // 09.06.06 14:00

                MarkerOverlayItem item = new MarkerOverlayItem(p, points.size() 
+
"", "Lat: "
                                + p.getLatitudeE6() + "\nLong: " + 
p.getLongitudeE6() + "\n" +
dateString + ": "
                                + date, points.size());
                item.date = date;
                overlays.add(item);

                points.add(p);
                setLastFocusedIndex(-1);
                populate();
        }

        public void repopulate() {
                populate();
        }

        public void addOverlays(List list) {
                for (Iterator iterator = list.iterator(); iterator.hasNext();) {
                        OverlayItem overlay = (OverlayItem) iterator.next();
                        overlays.add(overlay);
                }
                setLastFocusedIndex(-1);
                populate();
        }

        public void draw(Canvas canvas, MapView view, boolean shadow) {
                // super.draw(canvas, view, false);

                int size = points.size();
                if (size == 0)
                        return;
                int rad = 15;
                RectF oval = null;
                Point lastPoint = new Point();

                        GeoPoint p = points.get(0);
                        view.getProjection().toPixels(p, lastPoint);
                        int x = lastPoint.x;
                        int y = lastPoint.y;
                        oval = new RectF(x - rad, y - rad, x + rad, y + rad);
                        canvas.drawOval(oval, linePaint);

        }

        @Override
        protected OverlayItem createItem(int i) {
                return overlays.get(i);
        }

        @Override
        public int size() {
                return overlays.size();
        }

        @Override
        protected boolean onTap(int index) {
                // anzeigen: Coordinaten, datum hinzugefĆ¼gt
                Log.d(ShowMap.TAG, "onTap " + index);

                return true;
        }

}

On 19 Jan., 18:17, Dudero <sinfanh...@googlemail.com> wrote:
> Hello
>
> I want to mark( with a colored point) all the the positions which are
> clicked on the screen.
>
> I found something like overriding the onTap(GeoPoint p, MapView)-
> Method of an Overlay, but I do not understand how to draw then this
> points into a MapView. Do i have to call the draw()-method for each
> new point?
>
> Of course the GeoPoint has to be transformed into pixel-format with
> the "getProjection().toPixels(GeoPoint gp,Point px)"-method.
>
> Can somebody give me a good template?
>
> Greetz dudero

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to