GeoTools is a set of javascript classes for performing conversions between WGS84 latitude and longitude coordinates, and Ordnance Survey Great Britain grid references and/or Ireland National Grid. 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="geotools2.js"></script>
NOTE: If you're developing a GreaseMonkey script, copy the entire geotools2.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(); wgs84.setDegrees(52.92281, -5.39794); //convert to Irish irish=wgs84.getIrish(); //get a grid reference with 3 digits of precision gridref = irish.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);
//create a irish coordinate irish=new GT_Irish(); irish.setGridCoordinates(526217, 223873); //convert to a wgs84 coordinate wgs84 = irish.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
And here's a live demonstration of conversion between WGS84 and Irish Grid....
WGS84 Decimal latitude and longitude
Irish Grid Ref
This class holds a WGS84 latitude and longitude and includes the following members
This class holds a OSGB36 Grid Reference and includes the following members
This class holds a Irish Grid Reference and includes the following members
This software is licenced under the GNU General Public Licence, yadda yadda