user1549053
user1549053

Reputation: 109

A simple way to draw on Google maps in Android

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.

Upvotes: 0

Views: 251

Answers (1)

Johnny Doe
Johnny Doe

Reputation: 3330

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;
    }

}

Upvotes: 1

Related Questions