Distance Object, release 1.0
Continuing my ongoing trickle of OpenSource releases, the next class to leave the Polaris Digital factory is distanceObject.
History
distanceObject was created for a project that involved a geocoding system that would search a database for nearby properties using a postcode supplied by the user. The geocoding system would return the distance between points in metres, whereas my client required miles.
Knowing full well there were probably a number of pre-written PHP scripts available on the net, I decided to ignore them all and create my own class. This class would do more than simply convert metres to miles, it would convert any of the popular metric measures to popular imperial measures and back again. Thus, distanceObject was born.
Usage
PHP (4,5)� distanceObject class (inputValue, inputUnit)
$my_distanceObject = new distanceObject(23.44, 'm'); print($my_distanceObject->getValue('mile')); // Prints : 0.014564941
Attributes
inputValue float The value of the distance you wish to convert; ie. 20.3453
inputUnit string The unit of the distance you wish to convert; ie. metres, inches, etc. etc.
Methods
getValue (unit) returns the distance value in the specified unit
Legal unit values for the constructor and the getValue() method are as follows
mm Millimetres
cm Centimetres
m Metres
km Kilometres
inch Inches
ft Feet
yard Yards
mile Miles
Download and Licence
distanceObject is released under the GNU Public Licence v2, the full licence is included with the file.

Leave a Reply
You must be logged in to post a comment.