2
Mon problème est que je veux créer une méthode que lorsque je l'appelle en lui donnant deux GeoPoint, je veux qu'il trace une ligne entre les deux points et je n'ai pas pu fais ceci.Tracer une ligne entre 2 points en utilisant Google Maps
Merci d'avance.
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
}
Méthode d'essai idéalement je voudrais passer 2 géopoints pour tracer une ligne entre les
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();
}
Afficher ce que vous avez essayé serait déjà génial! –
J'ai pris le code que j'ai d'un exemple ici sur stackoverflow. Où ils font tout le code de test dans la fonction draw, la chose est que je veux avoir une ligne chaque fois que j'appelle la fonction comme ajouter une superposition à l'ArrayList et je n'ai aucune idée de comment être honnête. – andre
J'ai pris le code que j'ai d'un exemple ici sur stackoverflow. Où ils font tout le code de test dans la fonction draw, la chose est que je veux tracer une ligne chaque fois que j'appelle la fonction, comme ajouter une superposition à ArrayList et je n'ai aucune idée de comment le faire pour être honnête. – andre