I have code from openlayers that I cannot quite handle because I am so new for these kind of codes. My main goal is to measure area from n amount of lat/lon gps coordinates and convert the result into square kilometres.
I have adopted some code from the post here and it seems almost ready but I was not able to figure out how to use it with my test coordinates that are
var lats = [25.767368, 34.088808, 40.727093]
var lons = [-80.18930, -118.40612, -73.97864];
Which I need to use in code like this to get the area and finally convert it into square kilometres. Any help with this? Please make it simple as this is pretty much my first attempt on geagraphic coding.
var area = 0.0;
var len = ring.components && ring.components.length;
if (len > 2) {
var p1, p2;
for (var i=0; i<len-1; i++) {
p1 = ring.components[i];
p2 = ring.components[i+1];
area += OpenLayers.Util.rad(p2.x - p1.x) *
(2 + Math.sin(OpenLayers.Util.rad(p1.y)) +
Math.sin(OpenLayers.Util.rad(p2.y)));
}
area = area * 6378137.0 * 6378137.0 / 2.0;
}