# How can I measure area in square kilometres from lat / lon gps coordinates?

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) *

}

area = area * 6378137.0 * 6378137.0 / 2.0;

}
``````

I write this html script for you from this formule, x and y are taken from your example.

Edit : This code was written for your previous question in which you are looking for a javascript code (This question has been deleted). I'm sorry if I'm off topic and I hope this code will help you anyway.

``````<!DOCTYPE html>
<html>
<meta charset="utf-8" />
<title>Titre</title>
<body>
<script type="text/javascript" src="code.js">
// Converts from degrees to radians.
return degrees * Math.PI / 180;
};

x1 = 25.767368;
x2 = 34.088808;
x3 =40.727093;
x4 = ;
y1 = -80.18930;
y2 = -118.40612;
y3 = -73.97864;
y4 = ;