Thanks, onion and pickle, for your suggestions. (All we need now for a sandwich is some cheese.)
The problem I have is that I might want to initialise the Position with an Ordnance Survey (OS) grid reference or with a latitude/longitude. For example, $pos1 and $pos2 are both centred on London:
Code: Select all
$pos1 = new Position();
$pos1->setOSGrid(530, 180);
$pos2 = new Position();
$pos2->setLatLong(51.5, -0.126);
$grid1 = $pos1->getOSGrid(); // returns array(530, 180);
$grid2 = $pos2->getOSGrid(); // returns array(530, 180);
I suppose I could modify the constructor further to include an indication of the type of data being supplied:
Code: Select all
function __construct($type, $eastlat, $northlong)
...
and then
Code: Select all
$pos1 = new Position(Position::POSITION_TYPE_OSGRID, 530, 180);
$pos2 = new Position(Position::POSITION_TYPE_LATLONG, 51.5, -0.126);
$grid1 = $pos1->getOSGrid(); // returns array(530, 180);
$grid2 = $pos2->getOSGrid(); // returns array(530, 180);
I suppose that would do, it's just not quite as neat as I'd hoped for.