Jump to the following:

We use cookies to improve this website. Read about cookies

OS OpenSpace: Grid reference from Eastings & Northings

Supplied by our customer Bill Chadwick

Use the code snippet below to make an OS grid reference.

Use getEasting and getNorthing on a MapPoint to get the values to pass in to this, return is a string.

//convert northing and easting to letter and number grid system (5 figure grid)
function NE2NGR( east,  north)
{
var eX = east / 500000;
var nX = north / 500000;
var tmp = Math.floor(eX) - 5.0 * Math.floor(nX) + 17.0; 
nX = 5 * (nX - Math.floor(nX));
eX = 20 - 5.0 * Math.floor(nX) + Math.floor(5.0 * (eX - Math.floor(eX)));
if (eX > 7.5) eX = eX + 1; // I is not used
if (tmp > 7.5) tmp = tmp + 1; // I is not used

var eing = east - (Math.floor(east / 100000)*100000);
var ning = north - (Math.floor(north / 100000)*100000);
var estr = eing.toFixed(0);
var nstr = ning.toFixed(0);
while(estr.length < 5)
	estr = "0" + estr;
while(nstr.length < 5)
	nstr = "0" + nstr;

var ngr = String.fromCharCode(tmp + 65) + 
          String.fromCharCode(eX + 65) + 
          " " + estr + " " + nstr;
return ngr;
}

We hope you find this useful.

Back to top
© Ordnance Survey 2016
Be sure to take a look at our Terms of Use and Privacy Policy