GeoTools is a set of javascript classes for performing conversions between WGS84 latitude and longitude coordinates, and Ordnance Survey Great Britain grid references. It has similar performance to the conversion carried out by a typical GPS receiver, and is accurate to approximately 7m for 90% of Great Britain
The classes are particularly useful for developing "GreaseMonkey" scripts which bolt additional functionality onto existing sites through Javascript
If you're the type that doesn't read manuals, here's how to get up and running
<script language="javascript" src="geotools.js"></script>
NOTE: If you're developing a GreaseMonkey script, copy the entire geotools.js into your script.
//create a wgs84 coordinate wgs84=new GT_WGS84(); wgs84.setDegrees(51.59762, -2.39794); //convert to OSGB osgb=wgs84.getOSGB(); //get a grid reference with 3 digits of precision gridref = osgb.getGridRef(3);
//create a wgs84 coordinate wgs84=new GT_WGS84(); var str="N 51° 53.947 W 000° 10.018"; var ok = wgs84.parseString(str); if (ok) { //coordinate parse ok, now we can work with it osgb=wgs84.getOSGB(); }
//create a osgb coordinate osgb=new GT_OSGB(); osgb.setGridCoordinates(526217, 223873); //convert to a wgs84 coordinate wgs84 = osgb.getWGS84(); //now work with wgs84.latitude and wgs84.longitude alert("Latitude "+ wgs84.latitude + " Longitude "+wgs84.longitude);
Here's a live demonstration of conversion between WGS84 and OSGB Grid....
WGS84 Decimal latitude and longitude
OSGB Grid Ref
This class holds a WGS84 latitude and longitude and includes the following members
This software is licenced under the GNU General Public Licence, yadda yadda