Thursday, 23 June 2011

Draw Circle



package utils
{
import com.google.maps.LatLng;
import com.google.maps.Map3D;
import com.google.maps.overlays.Polygon;
import com.google.maps.overlays.PolygonOptions;
import com.google.maps.styles.FillStyle;
import com.google.maps.styles.StrokeStyle;


public class DrawCirclePolygonUtil
{
public function DrawCirclePolygonUtil()
{

}

/**
* This method draws a circle polygon in the map
* @Param latitude, longitude, radius, etc.
*/
public function drawCircle(lat:Number, lng:Number, radius:Number, mapRef:Map3D):void
{
var circleLat:Number = radius * 0.014483;  // Convert miles into degrees latitude
var circleLng:Number = circleLat/Math.cos(lat*(Math.PI/180));
var circleLatLngs:Array = new Array();
var circlePolygon:Polygon;

var polygonOptions:PolygonOptions = new PolygonOptions
(({
StrokeStyle: new StrokeStyle({color: 0x000080,thickness: 10,alpha: 0.75, width: 1}),
FillStyle: new FillStyle({color: 0xFFFFFF, alpha: .5})
}));

for (var i:Number = 0; i< 33; i++)
{
var theta:Number = Math.PI * (i/16);
var vertexLat:Number = lat + (circleLat * Math.sin(theta));
var vertexLng:Number = lng + (circleLng * Math.cos(theta));
var latLng:LatLng = new LatLng(vertexLat, vertexLng);

circleLatLngs.push(latLng);
}

circlePolygon = new Polygon(circleLatLngs, polygonOptions);
mapRef.addOverlay(circlePolygon);
}
}
}

No comments:

Post a Comment