Download the PHP package becklyn/postal-code-proximity without Composer
On this page you can find all versions of the php package becklyn/postal-code-proximity. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download becklyn/postal-code-proximity
More information about becklyn/postal-code-proximity
Files in becklyn/postal-code-proximity
Package postal-code-proximity
Short Description Calculates near postal codes (given, that a pre-generated postal code lookup database exists).
License BSD-3-Clause
Homepage https://github.com/Becklyn/BecklynPostalCodeProximity
Informations about the package postal-code-proximity
Becklyn Postal Code Proximity
If you have a pre-generated database with a mapping of postal codes to latitude & longitude, this library will help you with searching for nearby postal codes (in a given radius).
Usage
First you need to create a query generator. The query generator is responsible for generating the SQL for loading the data from the database. You need to specify the names of the table and the columns of your postal code table.
Afterwards, you need to use a database adapter. There are already working adapters for PDO and mysqli.
or
And now you can query for nearby postal codes:
$postalCode
is the postal code, like"12345"
$radius
is the radius in km (air-line distance)$limit
(optional) limit the number of results
Return value
You will receive an array of NearPostalCode
Error cases
There are two possible error case (except of exceptions directly from the databases):
AmbiguousPostalCodeException
: if a given postal code is found multiple times in the postal code databaseQueryException
: handles all error cases originating in the database. Warning: the exception messages may contain sensitive information.
Recommended database structure
postal_code CHAR(5)
(may vary depending on your country of origin)latitude DOUBLE
longitude DOUBLE
You should add an unique index to the postal_code
fields and indexes on latitude
and longitude
.