PHPcoord

Easily convert between latitude/longitude, Universal Transverse Mercator (UTM) and Ordnance Survey (OSGB) references with PHP using the PHPcoord package.
Latest version: 2.3 (24th August 2006)

Features | Requirements | Download | Examples | Version History | Licensing

Conversion between latitude/longitude and grid references is not as simple as one would expect. Indeed, the maths involved is rather complex and not really for the faint-hearted! I have created a PHP script which provides a simple API to allow conversion between OSGB (Ordnance Survey of Great Britain) grid references, UTM (Universal Transverse Mercator) references and latitude/longitude. OSGB Grid references can be returned as a standard six-figure grid reference using the 100km grid square letters (e.g. SK619847).

The PHPcoord script also contains a function to allow the calculation of the surface distance between two points of latitude/longitude.

Looking for the same thing but with JavaScript or Java? Translations of this package with the same functionality are available for JavaScript (see JScoord) and Java (see Jcoord).

Information on converting between UTM and latitude/longitude is available at www.posc.org.

The Ordnance Survey have published a concise guide on converting between OSGB and latitude/longitude which is available at www.gps.gov.uk.

Bear in mind that PHPcoord is still in development, so check back often for updates. To contact me about PHPcoord, send an e-mail to phpcoord@jstott.me.uk.

Features

PHPcoord contains the following features:

Requirements

You just need an installation of PHP 4 or 5 for PHPcoord to work.

Download

Current Version

Previous Versions

Examples

Converting co-ordinates is painless using PHPcoord. Here's an example of converting an Ordnance Survey grid reference into a latitude and longitude and displaying the result:

$os1 = new OSRef(651409.903, 313177.270);
echo "OS Grid Reference: " . $os1->toString() . " - " . $os1->toSixFigureString() . "<br />";
$ll1 = $os1->toLatLng();
echo "Converted to Lat/Long: " . $ll1->toString();
OS Grid Reference: (651409.903, 313177.27) - TG514132
Converted to Lat/Long: (52.657570301933, 1.7179215806451)

The PHPcoord downloads contain a test.php file which shows how to use the phpcoord.php script. You can also view the output of the test.php script which includes the above example and many more here.

Version History

Licensing

This software product is available under the GNU General Public License (GPL) which permits the use of this product subject to a number of conditions as described in the license. A commercial license is also available for this product which provides the added benefits of royalty-free use and distribution in proprietary applications as well as prioritised technical support by e-mail. Contact me for more information about commercial licenses for this product.

Solution Graphics

If you do not require a commercial license but still want to contribute, perhaps you would like to consider making a donation:

Commercial licenses for this product are available at the following prices:

Note that you will be billed in Pounds Sterling, so the relevant exchange rate from your currency will apply at the time of purchase. A copy of the license will be forwarded to the address provided at the time of purchase.

Save up to $90 with Dreamhost