//Reference: http://www.code322.com/gmap/?ex=circle1

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


//exec   drawCircle(40.77,-73.98, 10,   360,    gmap, "#009900",    1,            1,  "#00ff00",         0.2);
function drawCircle(lat, lng, radius_mi, points, map, edge_color, weight, edge_opacity, fill_color, fill_opacity)
{
    var rlat = (radius_mi / earthsradius) * r2d;
    var rlng = rlat / Math.cos(lat * d2r);
    var extp = new Array();
    var circleBounds = new GLatLngBounds();
    for (var i=0; i < points+1; i++) {
      var theta = Math.PI * (i / (points/2));
      ex = lng + (rlng * Math.cos(theta));
      ey = lat + (rlat * Math.sin(theta));
      extp.push(new GPoint(ex, ey));
      circleBounds.extend(new GLatLng(ey, ex)); // lat, lng // ex, ey
    }
    map.addOverlay(new GPolygon(extp, edge_color, weight, edge_opacity, fill_color, fill_opacity));

	// Zoom to circle bounds
	map.setZoom(map.getBoundsZoomLevel(circleBounds));

	// Center on circle bounds
	map.setCenter(circleBounds.getCenter());
}