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)
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.
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 email@example.com.
PHPcoord contains the following features:
- Calculate distance between a pair of latitudes and longitudes
- Convert between an OSGB grid reference and latitude and longitude using either the OSGB36 or WGS84 data
- Create objects representing OSGB grid references from a six-figure reference string (e.g. "TG514131")
- Convert between UTM reference and latitude and longitude
You just need an installation of PHP 4 or 5 for PHPcoord to work.
- v2.2 - 11th February 2006
- v2.1 - 22nd December 2005
- v2.0 - 21st December 2005
- v1.1 - 11th September 2005
- v1.0 - 11th August 2005
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.
- 2.3 - 24th August 2006
- Changed OSRef->toSixFigureString() so that the eastings and northings are rounded rather than floored.
- 2.2 - 11th February 2006
- Used different algorithm for calculating distance between latitudes and longitudes - fixes a number of problems with distance calculations.
- 2.1 - 22nd December 2005
- Added getOSRefFromSixFigureReference to convert a string representing a six-figure OS grid reference to an OSRef object.
- 2.0 - 21st December 2005
- Completely different object design - conversion functions now through objects rather than static functions.
- Updated comments and documentation
- 1.1 - 11th September 2005
- Added WGS84/OSGB36 conversions.
- 1.0 - 11th August 2005
- Initial Version.
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.
If you do not require a commercial license but still want to contribute, perhaps you would like to consider making a donation:
Donation - any amount
Commercial licenses for this product are available at the following prices:
Single user - £15 (approximately $30)
2-10 users - £40 (approximately $80)
11-100 users - £150 (approximately $300)
Unlimited users - £600 (approximately $1200)
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.
© 2000-11, Jonathan Stott.
23 Oct 2016 07:47:09 GMT