J'ai besoin de dessiner un polygone à partir de plusieurs points (j'ai leur latitude, leur longitude). Je fonde ma mise en œuvre de ces deux réponses: Drawing an empty polygon given a set of points on a Map Overylay (Android 2.1) Drawing a line/path on Google MapsToile pour dessiner un polygone sur une carte dans Android
Dans mon MapOverlayAction.java je mets la superposition pour certains axes comme celui-ci:
mapOverlays.add(itemizedoverlay);
setLocationOverlay(mapView, mapController);
où itemizedoverlay est un tableau de OverlayItems
Cela fonctionne très bien. Mais j'ai aussi besoin de dessiner un polygone pour ces points (où chaque point est un sommet). Alors ce que je fais est:
Path path = new Path();
for (int j = 0; j < itemizedoverlay.size(); j++) {
GeoPoint gP1 = itemizedoverlay.getItem(j).getPoint();
Point currentScreenPoint = new Point();
Projection projection = mapView.getProjection();
projection.toPixels(gP1, currentScreenPoint);
if (j == 0)
path.moveTo(currentScreenPoint.x, currentScreenPoint.y);
else
path.lineTo(currentScreenPoint.x, currentScreenPoint.y);
}
Dans les deux answersI fonder ma solution, la méthode suivante est appelée:
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(2);
canvas.drawPath(path, mPaint);
Ma question est, où dois-je obtenir cette toile de? J'ai tout ce code dans ma classe d'activité.
Merci!
Merci, j'utilise cette question sur ma solution comme je l'ai cité dans ma question. Quoi qu'il en soit, maintenant j'ai essayé exactement comme la réponse dit (et comme vous l'avez dit que cela devrait être fait et ça marche) je pensais juste que cela pourrait être fait d'une autre manière. Merci – marimaf