I want to draw with my finger an overlay on google maps. I already accomplished that the line is drawn.. But the map moves also with my finger and so i cant draw very well, because i just can draw a small circle around my finger when the map also moves...
How can i disable the movement (dragging) of the map and be still able to draw and display an overlay with my finger?
My current Code looks like this:
public class OverlayMap extends Overlay {
private List<MapGeoLine> geoLines = new ArrayList<MapGeoLine>();
private List<GeoPoint> geoPoints;
private boolean isTouched = false;
@Override
public boolean onTouchEvent(MotionEvent motionEvent, MapView mapView) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
geoPoints = new ArrayList<GeoPoint>();
geoPoints.add(mapView.getProjection().fromPixels((int)motionEvent.getX(),(int)motionEvent.getY()));
isTouched = true;
}
if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){
if(isTouched){
geoPoints.add(mapView.getProjection().fromPixels((int)motionEvent.getX(),(int)motionEvent.getY()));
}
}
if(motionEvent.getAction() == MotionEvent.ACTION_UP){
if(isTouched){
geoPoints.add(mapView.getProjection().fromPixels((int)motionEvent.getX(),(int)motionEvent.getY()));
}
isTouched = false;
}
return super.onTouchEvent(motionEvent, mapView);
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
if(geoPoints != null && geoPoints.size() > 1 && !isTouched){
Paint mPaint = new Paint();
mPaint.setStrokeWidth(2);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setAntiAlias(true);
Projection projection = mapView.getProjection();
Point from = new Point();
Point to = new Point();
Path p = new Path();
projection.toPixels(geoPoints.get(0), from);
for(int i = 1; i < geoPoints.size(); i++){
projection.toPixels(geoPoints.get(i), to);
p.moveTo(from.x, from.y);
p.lineTo(to.x, to.y);
from.set(to.x, to.y);
}
canvas.drawPath(p, mPaint);
mapView.invalidate();
}
super.draw(canvas, mapView, shadow);
}
}