var areaNumber:Number = areaFromLatLngs(*your poly points array here*);
private function areaFromLatLngs(polyPoints:Array):Number
{
var arr:Array = methodConvertFromPolypointsToPoints(polyPoints);
return area(arr);
}
private function
methodConvertFromPolypointsToPoints(polyPoints:Array):Array
{
var latlng1:LatLng = null;
var p1:Point = null;
var latlng2:LatLng = null;
var p2:Point = null;
var num1:Number = NaN;
var num2:Number = NaN;
var arr1:Array = polyPoints.slice(0,polyPoints.length);
var arr2:Array = [];
if (arr1[0].lat() != arr1[(arr1.length - 1)].lat() ||
arr1[0].lng() != arr1[(arr1.length - 1)].lng())
{
arr1.push(new LatLng(arr1[0].lat(), arr1[0].lng()));
}
arr2.push(new Point(0, 0));
var count:int = 1;
while (count < arr1.length)
{
latlng1 = arr1[count];
p1 = map.fromLatLngToPoint(latlng1);
latlng2 = arr1[(count - 1)];
p2 = map.fromLatLngToPoint(latlng2);
num1 = Math.atan2(p1.y - p2.y, p1.x - p2.x);
num2 = latlng1.distanceFrom(latlng2);
arr2.push(new Point(arr2[(count - 1)].x + Math.cos(num1) *
num2, arr2[(count - 1)].y + Math.sin(num1) * num2));
count++;
}
return arr2;
}
private function area(polyPoints:Array):Number
{
var i:int = 0;
var j:int = 0;
var area:Number = 0;
i = 0;
while(i < polyPoints.length)
{
j = (i + 1) % polyPoints.length;
area = area + polyPoints[i].x * polyPoints[j].y;
area = area - polyPoints[i].y * polyPoints[j].x;
i++;
}
area = area * 0.5;
return Math.abs(area);
}
you will get number to "*areaNumber*" using above code....
call the areaToMeasureFormat(*areaNumber) *will return area in different
types of measurement as below
public function areaToMeasureFormat(*areaNumber*:Number):String
{
var str:String = null;
if (*areaNumber*> 1000000)
{
str = Number(*areaNumber */ 1000000).toFixed(2)) + " km² ";
}
str = Number(*areaNumber*) * 3280.8399).toFixed(2)) + " ft / ";
if (Number(*areaNumber* * 10.7639) > 43560)
{
str = str + (Number(*areaNumber* * 10.7639 /
43560).toFixed(2)) + " acres");
}
else
{
var yard:Number = Number(*areaNumber* * 10.7639)/3;
str = str + (yard.toFixed(2) + " yards ");
}
return str;
}
On Fri, Oct 22, 2010 at 4:52 PM, Athlantanis
<[email protected]>wrote:
> Hello,
>
> I tried to calculate the surface of a area with google map.
> This surface is draw by the user (with polygon class) and can contain a lot
> of point.
> I want to calculate the surface of this area but i don't know how i can do
> that ...
>
> I tried to calculate the threhold for the area to have the surface in pixel
> and after multiply by a scale, but it doesn't work.
> I don't find function (if it exist) to do that.
>
> Is it possible to do that and if it's possible, how can i do ?
> Thank,
> Olivier
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps API For Flash" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-api-for-flash%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-api-for-flash?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Google Maps API For Flash" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api-for-flash?hl=en.