views:

51

answers:

2

Hello,

I am new to Android development and I have a problem that I have been working on for hours with no success. I want to create a cross-hair in the center of my Google map that stays in the center even when the map is panned. I have a .png image of the cross-hair in my drawable directory. Additionally, I have a MapView that displays the Google map with several markers. What is the best way to approach this problem?

Any help is greatly appreciated.

Thank you,

Tuong

A: 

You will need to make a CrosshairOverlay. Haven't tested this.

public class CrosshairOverlay extends Overlay {

     void draw(Canvas canvas, boolean shadow, Mapview mapView) {
          Geopoint centerGp = mapView.getCenter();
          Projection projection = mapView.getProjection();
          Point centerPoint = projection.toPixels(centerGp, null);
          Paint p = new Paint(); //configure it, should be a field.
          canvas.drawCircle(p.x, p.y, innerRadius, p);
          canvas.drawCircle(p.x, p.y, outerRadius, p);
     }
}
BrennaSoft
Thank you! With a few edits, I was able to make it to work.
A: 
public class CrossHairsOverlay extends Overlay {
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
        super.draw(canvas, mapView, shadow);
        GeoPoint centerGp = mapView.getMapCenter();
        Projection projection = mapView.getProjection();
        Point centerPoint = projection.toPixels(centerGp, null);
        Paint p = new Paint();
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.crosshairs_dial);
        canvas.drawBitmap(bmp, centerPoint.x, centerPoint.y, p);
        return true;
    }
}