我的问题是我想创建一个方法,当我调用它时给它两个 GeoPoint,我希望它在两点之间画一条线,但我无法做到这一点。
提前致谢。
public class MyOverlays extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context context;
private int lastestIndex;
private Projection projection;
private Canvas canvas;
private MapView mapv;
private boolean shadow;
public MyOverlays(Context context, Drawable defaultMarker, String player) {
super(boundCenterBottom(defaultMarker));
this.context = context;
}
@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
@Override
public int size() {
return mapOverlays.size();
}
public void setPj(Projection projection) {
this.projection = projection;
}
public void draw(Canvas canvas, MapView mapv, boolean shadow) {
super.draw(canvas, mapv, shadow);
this.canvas = canvas;
this.mapv = mapv;
this.shadow = shadow;
// Configuring the paint brush
}
理想情况下的测试方法我想通过 2 个地理点在它们之间画一条线
public void test() {
super.draw(canvas, mapv, shadow);
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(4);
GeoPoint gP1 = new GeoPoint(34159000, 73220000);// starting point
GeoPoint gP2 = new GeoPoint(33695043, 73050000);// End point Islamabad
GeoPoint gP4 = new GeoPoint(33695043, 73050000);// Start point Islamabad
GeoPoint gP3 = new GeoPoint(33615043, 73050000);// End Point Rawalpindi
Point p1 = new Point();
Point p2 = new Point();
Path path1 = new Path();
Point p3 = new Point();
Point p4 = new Point();
Path path2 = new Path();
projection.toPixels(gP2, p3);
projection.toPixels(gP1, p4);
path1.moveTo(p4.x, p4.y);// Moving to Abbottabad location
path1.lineTo(p3.x, p3.y);// Path till Islamabad
projection.toPixels(gP3, p1);
projection.toPixels(gP4, p2);
path2.moveTo(p2.x, p2.y);// Moving to Islamabad location
path2.lineTo(p1.x, p1.y);// Path to Rawalpindi
canvas.drawPath(path1, mPaint);// Actually drawing the path from
// Abbottabad to Islamabad
canvas.drawPath(path2, mPaint);// Actually drawing the path from
// Islamabad to Rawalpindi
this.populate();
}