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.
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.
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:
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.
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.
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.
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.