-
Notifications
You must be signed in to change notification settings - Fork 0
Methods
tipichris edited this page Sep 14, 2010
·
9 revisions
Create a new instance. $driver is the driver to be used, currently one of ‘textfile’, ‘mysql’, ‘uk_postcodes’, ‘ukgeocode’, ‘geopostcode’ or ‘openlylocal’. Valid values for $params depend on the driver chosen. See Drivers for more information.
Initialise the connection to the back end. This must always be called before any functions needing to look up postcodes can be called.
Sets the value of the separator between outward (SW1A) and inward (1AA) parts of the postcode data. The default depends on the driver. It is a single space usually, but an empty string for uk_postcodes. The use of an empty string is not recommended if your data also includes means or midpoints for districts and sectors, because this can be ambiguous. Eg ‘B11’ could be either the district B11 or the sector B1 1.
Indicates that the geo data is in wgs84 (latitude and longitude) format. Note that when using the mysql driver if you do not specify the sql parameter in the paramaters passed to factory() and you are using wgs84 you must call use_wgs84() before calling loaddata. This is because the default SQL is dependent on the co-ordinate scheme being used.
Indicates that the geo data is in osgb36 (British national grid) format.This is the default.
Note that the uk_postcodes driver (which uses http://www.uk-postcodes.com) can provide data in either wgs84 or osgb36. The latter makes distance calculations less demanding
Tests if a postcode is valid and known in the database. Returns the found code on success, false on failure.
If the full code is not found, checks will be made for matches by sector (SW1A 1), district (SW1A) and area (SW1). The return value is the best match.
eg, for SW1A 1AA
Returns false on failure
Checks if $postcode1 is the same postcode as $postcode2.
Returns true if the same, false otherwise
Like validcode(), if an exact match isn’t available calc_distance will match on sector, district or area.
Returns false on failure.
If $exactmatch is true (defaults to false), matches only if the $postcode is known (after normalising $postcode).
Sets the smallest unit that will be checked for by validcode() 1: Area only: SW 2: District: SW1A 3: Sector: SW1A 1 4: Unit: SW1A 1AA Returns an array containing the location of the postcode. The elements are (eastings, northings) for osgb36 or (latitude, longitude) for wgs84 Takes a postcode or partial postcode and attempts to split it into component parts. Returns an array:
[0] => Area,
[1] => District
[2] => Sector
[3] => Unit
[0] => SW
[1] => 1A
[2] => 1
[3] => AA
Returns a normalised version of $postcode, taking account of the current setting of $inoutsep
calculate the distance between $fromcode and $tocode. $options is an optional array:
unit => 'miles'|'km' The unit to return the distance in (default miles)
decimal => int The number of decimal places (defalt 0)
returns the last error message generatedNB 0 is a valid, good response indicating a distance of 0km or 0miles. Be sure to test for false (eg if($d === false)