0

I am looking for a simple way to draw small icons on a Google map activity in android. Nothing fancy, I just want to put in longitude and latitude and a few other properties, and to have it as a clickable little icon on the appropriate position on the map. When clicked, it would give out some other data on the screen, but firstly, I need a way to draw them onto the map.

Flexo
  • 87,323
  • 22
  • 191
  • 272
user1549053
  • 109
  • 3
  • 8

1 Answers1

1

Take a look on Overlay and ItemizedOverlay classes. It seems ItemizedOverlay meets your requirements. Here is little tutorial to use it. On Overlay you can draw more complicated shapes - just override it's draw() method with your's. For example:

public class Road extends Overlay {
//some your code...

@Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { drawPath(mapView, canvas); }

private void drawPath(MapView mv, Canvas canvas) {
    int x1 = -1;  
    int y1 = -1;
    int x2 = -1;
    int y2 = -1;

    Point point = new Point();

    for (int i=0; i < list.size(); i++) {
        mv.getProjection().toPixels(list.get(i), point);
        x2 = point.x;
        y2 = point.y;

        if (i > 0) {
            canvas.drawLine(x1, y1, x2, y2, paint);
        }

        x1 = x2;
        y1 = y2;
    }

}

Johnny Doe
  • 3,280
  • 4
  • 29
  • 45