Also ich mache ein Spiel für Android und ich muss Regionen oder Polygone in einem Google Maps-Fenster überlagern.Problem mit dem Zeichnen von Polygonen auf einem Google Maps Anzeigen auf Android
class polygonOverlay extends Overlay {
//this is the array of vertices we need to draw
GeoPoint[] vet;
Point[] points;
private float[] fVet;
//get the vertices
public polygonOverlay(GeoPoint[] v) {
vet = v;
points = new Point[v.length];
fVet = new float[(v.length)*2];
}
//this is how we draw it.
@Override
public void draw(Canvas canvas, MapView mapv, boolean shadow) {
super.draw(canvas,mapv, shadow);
//do some things
//set all the points to a point.
for(int i = 0; i < points.length; i++) {
points[i] = new Point();
}
//convert from the array of geoPoints to the array of points using the projection.
for(int i = 0; i < vet.length; i++){
projection.toPixels(vet[i], points[i]);
}
//convert the point to the float array
for(int i = 0; i < points.length; i++) {
fVet[2*i] = points[i].x;
fVet[(2*i)+1] = points[i].y;
}
//things be done...
//create a array of int colors.
int[] colorArray = new int[points.length];
for(int i = 0; i < points.length; i++) {
colorArray[i] = Color.RED;
}
//if we are drawing a shadow, then dont draw anything
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);
//lets draw some things.
canvas.drawLine(points[1].x, points[1].y, 200, 200, mPaint);
canvas.drawVertices(
Canvas.VertexMode.TRIANGLES,
fVet.length,
fVet,
0,
null,
0,
colorArray,
0,
null,
0,
0,
mPaint
);
}
}
das Problem ist jedoch, dass es nicht die Polygone zeigen:
Bisher habe ich folgendes gemacht. Ich habe alles probiert und war bis 2 Uhr morgens letzte Nacht, aber es funktioniert einfach nicht.
Ich fange an, dass sie mein Handy nicht mein Code zu denken ...
kann jeder sehen, was ich falsch gemacht habe?
Haben Sie versucht, zunächst etwas Einfaches auf die Leinwand zu zeichnen? – Benoir
yep ich tat, ich zeichnete eine Linie, es funktioniert. es ist nur die drawVertices, die nicht funktioniert –