MapView (Overlay): Punkte auf Kreis

  • 1 Antworten
  • Letztes Antwortdatum
H

henningp

Neues Mitglied
0
Hallo zusammen,

ich verzweifle gerade an folgendem Problem:
Ich habe ein Overlay, welches mir an einer gegebenen Position einen Kreis zeichnet. Soweit so gut, das funktioniert wie erwartet.

Code:
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, shadow);
        Projection projection = mapView.getProjection();
        
        GeoPoint position = new GeoPoint((int) (latitude * 1e6), (int) (longitude * 1e6));

        Point point = projection.toPixels(position, null);
        float radius = projection.metersToEquatorPixels(r) * (1 / FloatMath.cos((float) Math.toRadians(latitude)));

        canvas.drawCircle((float) point.x, (float) point.y, radius, getCirclePaint());
    }
Jetzt habe ich allerdings noch einen Anfangswinkel und einen Endwinkel, es soll also kein kompletter Kreis gezeichnet werden, sondern nur der Ausschnitt der beiden angegebenen Winkel. Bei Anfangswinkel 0° und Endwinkel 90° quasi der rechte obere Quadrant.
Ich vermute, dass ist dort mit drawArc arbeiten kann. Allerdings habe bereits Probleme die beiden Punkte (Anfangswinkel,Endwinkel) auf dem Kreis darzustellen. Ich hab es so versucht:
Code:
double latEnd = latitude * 1E6 + (r * Math.sin(Math.toRadians(90)));
double longEnd = longitude * 1E6 + (r * Math.cos(Math.toRadians(90)));
GeoPoint geoPoint = new GeoPoint((int) latEnd, (int) longEnd);
Point point = new Point();
projection.toPixels(geoPoint, point);
canvas.drawPoint((float) point.x, (float) point.y, endPaint);
(analog dazu mit dem Startwinkel). Leider ist der Punkt an einer falschen Stelle. Longitude stimmt, Latitude ist falsch. Der Punkt ist nicht auf der Kreislinie, sondern viel näher am Mittelpunkt.

Wo habe ich den Denkfehler?

Vielen Dank schonmal im Vorraus!
 
Zuletzt bearbeitet:
Ist natürlich auch selten dämlich, wenn man versucht Gradangaben (Longitude, Latitude) mit nicht-umgerechneten Zahlen (latEnd, latStart) zu addieren ;).

Lösung war simpel. Anbei ein einfaches Beispiel:
Code:
public void draw(Canvas canvas, MapView mapView, boolean shadow) {         
  super.draw(canvas, mapView, shadow);         
  Projection projection = mapView.getProjection();                  
  GeoPoint position = new GeoPoint((int) (latitude * 1e6), (int) (longitude * 1e6));         
   Point point  = projection.toPixels(position, null);         
   float radius = projection.metersToEquatorPixels(r) * (1 / FloatMath.cos((float) Math.toRadians(latitude)));         
   canvas.drawCircle((float) point.x, (float) point.y, radius, getCirclePaint());

  double latEnd = radius * Math.sin(Math.toRadians(90))); 
  double longEnd = radius * Math.cos(Math.toRadians(90))); 
  int pointLat = (int) (point.x + latEnd);
  int pointLong = (int) (point.y + longEnd);
   Point point = new Point(pointLat, pointLong); 
  canvas.drawPoint((float) point.x, (float) point.y, endPaint);
}
 
Zurück
Oben Unten