den folgenden Code Mit Kreis zu zeichnen (aus Google Play-Dienste "Maps" Probe):Android Maps API v2 draw Kreis
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 auf anderen Teil der Welt gezeichnet wird:
Wie Sie Kreise sehen, sind nicht wirklich Kreise und sogar zweite ist Ellipse im Grunde.
Ich denke, dass "Anti-Aliasing" von Kreis abhängig von der Anzahl der Punkte in int numPoints
Variable.
- Was ist
int radius = 5
Variable in Beispielcode? Ich meine, welches Maß es ist? - Und Hauptfrage, was wäre die richtige Art der Zeichnung schönen Kreis mit gegebenem Radius in Meter? Etwas smiliar zu dem, was wir mit
canvas.drawCircle()
UPDATE --------------------
OK, nachdem die Verbesserung der Mathematik in api v1 hatte konnte ich ziehen „rechts“ Kreis:
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 des Kreises ich denke, ist etwas außer Kontrolle, und auf einig Zoomstufen Kreis könnte hässlich:
der Grund, warum Sie Ellipse sind immer es ist, weil die Mathematik auf die 'options.add (' ist sehr einfach und gibt vor, die Erde eine flache Oberfläche ist, genau wie vor Kopernikus. Wenn Sie es auf kleineren Flächen zeichnen Sie Wenn Sie einen präzisen Kreis haben wollen, müssen Sie die Mathematik so erweitern, dass sie die Form der Erde berücksichtigt. – Budius
@lija, Irgendein bestimmter Grund, eine Polylinie anstelle von Polygon zu verwenden der Kreis? Ich habe versucht, mit Polygon und ich habe die gleiche Ausgabe. Also, Sie haben eine Idee, welche von ihnen ist am besten zu verwenden? Vielen Dank. –
@ Archie.bpgc nicht wirklich, könnten Sie Polygone verwenden, wenn Sie eine benötigen Fülloption zum Beispiel, sonst ist das in diesem Fall kein großer Unterschied –