Android Maps API v2-Kreis zeichnen

Nachdem Sie den folgenden code zum zeichnen der Kreis (entnommen aus Google Play-Dienste "maps" - Beispiel):

    PolylineOptions options = new PolylineOptions();
    int radius = 5; //What is that?
    int numPoints = 100;
    double phase = 2 * Math.PI / numPoints;
    for (int i = 0; i <= numPoints; i++) {
        options.add(new LatLng(SYDNEY.latitude + radius * Math.sin(i * phase),
                SYDNEY.longitude + radius * Math.cos(i * phase)));
    }
    int color = Color.RED;
    mMap.addPolyline(options
            .color(color)
            .width(2));

Dies ist, was gezeichnet auf dem anderen Teil der Welt:

Android Maps API v2-Kreis zeichnen
Android Maps API v2-Kreis zeichnen

Als Sie sehen, die Kreise sind nicht wirklich Kreise und sogar die zweite ist die ellipse im Grunde.

Ich denke mal, dass "anti-aliasing" der Kreis je nach Anzahl der Punkte in int numPoints variable.

  1. Was ist int radius = 5 variable im Beispiel-code? Ich meine, was es Messen?
  2. Und wichtigste Frage, was wäre die richtige Art, Zeichnung netten Kreis mit bestimmten radius in Meter? Etwas smiliar zu was wir in der api v1 mit canvas.drawCircle()

UPDATE --------------------

OK nach der Verbesserung Mathe war ich in der Lage zu zeichnen "richtigen" Lochkreis:

private void addCircle(LatLng latLng, double radius)
    {
        double R = 6371d; //earth's mean radius in km
        double d = radius/R; //radius given in km
        double lat1 = Math.toRadians(latLng.latitude);
        double lon1 = Math.toRadians(latLng.longitude);         
        PolylineOptions options = new PolylineOptions();
        for (int x = 0; x <= 360; x++)
        {                      
            double brng = Math.toRadians(x);
            double latitudeRad = Math.asin(Math.sin(lat1)*Math.cos(d) + Math.cos(lat1)*Math.sin(d)*Math.cos(brng));
            double longitudeRad = (lon1 + Math.atan2(Math.sin(brng)*Math.sin(d)*Math.cos(lat1), Math.cos(d)-Math.sin(lat1)*Math.sin(latitudeRad)));             
            options.add(new LatLng(Math.toDegrees(latitudeRad), Math.toDegrees(longitudeRad)));
        }           
        mMap.addPolyline(options.color(Color.BLACK).width(2));          
    }

Jedoch anti-aliasing der Kreis ist wohl etwas außer Kontrolle, und auf einige Zoomstufen Kreis könnte hässlich werden:

Android Maps API v2-Kreis zeichnen

InformationsquelleAutor der Frage Ilja S. | 2012-12-21

Schreibe einen Kommentar