Service by location

One of the features of the new.shropshire.gov.uk prototype site is the ability to find a service by location - for example, 'find my nearest' library. There are two main components to this. The first works out where you are and the second takes the data and provides a list of the three closest libraries to your location.

Finding your location

Automatically

A relatively new feature of most modern browsers is support for the HTML5 geolocation API which allows us to get the geographical location of a user via their device, such as a computer connected to the internet (using network data) or a Global Positioning System (GPS) device (e.g. mobile or tablet). It requires no manual input of address information and just works when the browser detects a location request (via javascript), making the process very simple to use.

It is an opt-in service, meaning that when the browser detects the request the user must accept it in order to share their location information with the API - if not accepted the request is ignored. Once accepted the browser receives the location information in the form of a pair of latitude and longitude coordinates. The accuracy of the returned result will depend on the device, for example devices using GPS are a lot more accurate than internet connected devices relying on network data (such as IP address or WiFi data).

For more information on the Geolocation API, visit the specification page.

Manually

We have also adopted a second method of getting location information from a user  because the geolocation API is not always suitable, such as in the following circumstances:

  • The user has an older browser which does not support the API, so cannot automatically find their location
  • The user wants to find the nearest library from some other location
  • A location result returned from the API is wrong

We use a simple postcode search to facilitate a manual location search and, for this prototype, the Google Geocoder API to translate that postcode into a pair of latitude and longitude coordinates. The coordinates will provide a much more generalised location than that of the geolocation API, as a postcode covers a larger area, but will still represent a geographically accurate position.

Library location

Each library (22 of them) has a pair of latitude and longitude coordinates which we assign by using a couple of text fields within the Umbraco content management system (CMS). We can then refer to these coordinates when working out which three libraries are closest to the location of the user.

For the prototype, we do this by using the Google Distance Matrix API, where we feed it the inputs of our user's location (start position) and all 22 library locations (finish positions). The API then returns a set of 22 results which contain the distances. We then order this list of results (closest-to-furthest) and pick out and show the details for the first three closest libraries.

Managing your location information

Once a location has been returned - either by the geolocation API or postcode search - we store the coordinates into two cookies. This is so that we do not have to keep requesting location information each time a user visits a 'find my nearest' type page. We also store any results (e.g. the three closest libraries) into another cookie so again we don't have to keep resending queries to Google's distance matrix API.

These cookies are stored for the duration of the user session and are automatically deleted when this ends. We have also included the option for users to manually remove these cookies at any time while the session is open to give them full control over their data.

Moving forward

As we add more service areas to the prototype site, we also plan to expand the 'find my nearest' feature, as the concept can be replicated for many other services, for example a 'find my nearest recycling point' or 'find my Councillor'. Our aim is to make our content a lot more specific to each individual visiting our website.