Download the PHP package lukaswhite/uk-postcode-geocoder without Composer

On this page you can find all versions of the php package lukaswhite/uk-postcode-geocoder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package uk-postcode-geocoder

Uk Postcode Geocoder

A geocoder (PHP) for UK postcodes, based on free open postcode data.

In simple terms, that means you can obtain the latitude and longitude of a postcode.

Data comes from the Office for National Statistics Postcode Directory, and is stored in an SQLite database for blazing fast lookups.

If you want to provide it as a self-hosted web service, you might find this repository useful.

A Note about Geocoding UK postcodes

There are a few different ways of geocoding postcodes, each with their own pros and cons; and indeed there is a key limitation to this library. That's the fact that the data set is not 100% complete. It's very comprehensive; there are currently over 2.6 million postcodes in it. However, PAF — that's the official data set from the Royal Mail — licenses are very expensive.

Because of this, you may need an alternative method such as Google Maps for those rare cases that a postcode is not in this database. However using this library means that the overwhelming majority of your geocoding requests will not incur a cost, and will not be subject to the overhead of using a third-party API.

The other alternative is postcodes.io, a free API for doing the same thing; albeit with additional information. This is based on the same ONS data, so if you use this package and keep the data up-to-date, then it's essentially the same as using this package, but with the overhead of an HTTP request. It's open source so you can host it yourself; the primary difference between that and this library is that it's written in Node.js; this is essentially an alternative for those working in a PHP environment.

Getting Started

Install the package using Composer:

Important: the data is not included in the package. This is due to the size of the file, and the fact that it's updated periodically.

The package does, however, include a bash script that will create and populate the database for you.

You'll find the data on the ONS Geo Portal, just search for "Postcode Directory".

At time of writing (November 2018), the latest file was published in August 2018.

The file you're looking for is a CSV with a filename similar to ONSPD_AUG_2018_UK.csv.

To run the setup process:

For example:

You may also run the provisioning process programmatically; it's all done using the Provisioner class; take a look at setup.sh to see how to use it.

Usage

Create an instance, passing it the directory which contains the SQLite database:

This assumes that the database filename is postcodes.sqlite, but you can override this:

Geocoding a Single Postcode

To geocode — that's to say, get the latitude and longitude of — a UK postcode, call the get() method:

The service is quite forgiving about the format; sw1a2aa would also work.

This returns an object that contains two key methods; getLatitude() and getLongitude(). It also includes a toArray() method, and implements the JsonSerializeable interface.

Geocoding Multiple Postcodes

You can also query multiple postcodes in one go with the getMultiple() method, for example:

This returns an associative array of instances of Coordinate, keyed by the properly formatted postcode.

Adding Postcodes

The data is comprehensive — over 2.6 million postcodes — but it's known not to be absolutely complete.

As such, you may need to use another source such as Google Maps if the postcode that you're looking up cannot be found. In such an instance you may wish to add it to this database, which you can do so using the add() method; for example:

Note that the library is quite forgiving about how you format the postcode, as you can see above. However passing an invald postcode will throw an InvalidPostcodeException. If the postcode is already in the database, it'll throw a DuplicatePostcodeException.


All versions of uk-postcode-geocoder with dependencies

PHP Build Version
Package Version
Requires catfan/medoo Version ^1.6
league/csv Version ^9.1
league/climate Version ^3.4
lukaswhite/uk-postcode Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lukaswhite/uk-postcode-geocoder contains the following files

Loading the files please wait ....