This documentation is not yet completed! Please give any feedback on the documentation and classes to paul [at sign] elphin [dot-com]

GeoTools WGS84/OSGB36 Converter for Javascript

See also Version 2 with WGS84/Irish Converter

Introduction

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

History

Quick Start

If you're the type that doesn't read manuals, here's how to get up and running

Include the script

<script language="javascript" src="geotools.js"></script>

NOTE: If you're developing a GreaseMonkey script, copy the entire geotools.js into your script.

Convert WGS84 to OSGB

//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);

Parse a WGS84 Coordinate

//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();
}

Convert OSGB to WGS84

//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);

Demonstration

Here's a live demonstration of conversion between WGS84 and OSGB Grid....

WGS84 Decimal latitude and longitude

OSGB Grid Ref

Reference Guide

GT_WGS84 Class

This class holds a WGS84 latitude and longitude and includes the following members

Licence

This software is licenced under the GNU General Public Licence, yadda yadda