Jump to the following:

Internet cookies at Ordnance Survey

We use cookies on this website in order to make your visit run more smoothly and to give us statistics that help us plan future enhancements. Learn more about the cookies we use.

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