Anonymous user  |  Log in  |  Create Account
Message inside General Discussions

Server side drawing circles

Answer 
#1 - 8/22/2011 6:24:32 PM Reporta abuso | PermaLink
milothegreat
Fecha de registro: 1/24/2010
1 post en todos los foros
Server side drawing circles

Answer Quote
I've had to write a server-side circle drawing method, it take into account of the earths curviture.

Credit to (http://www.missiondata.com/blog/systems-integration/44/approximating-a-circle-with-a-polygon/) for the original Javascript version

private
 void drawCircle2(double lat, double lng, double radius)
{
    // globals
    var d2r = Math.PI / 180;   // degrees to radians
var r2d = 180 / Math.PI;   // radians to degrees
    var earthsradius = 3963; // 3963 is the radius of the earth in miles
    var points = 32;    
//var radius = 10;    
double rlat = ((double)radius / earthsradius) * r2d;    
double rlng = rlat / Math.Cos(lat * d2r);    
List<GLatLng> extp = new List<GLatLng>();     
for (var i = 0; i < points + 1; i++)
    {
        double theta = Math.PI * (i / (double)(points / 2));
        double ex = lng + (rlng * Math.Cos(theta));
        double ey = lat + (rlat * Math.Sin(theta));
        extp.Add(new GLatLng(ey, ex));
    }
    this.GoogleMap2.addPolygon(new GPolygon(extp, "#00FF00", 0.3));
}
Radius is in Miles

EDITADO 8/22/2011 6:26:35 PM: Fix formatting

EDITADO 8/22/2011 6:27:50 PM: Added "Radius in Miles"
Top


Powered by Subgurim.NET