PostCode

  • Authors : Marc Palmer
0 vote
Dependency :
compile ":post-code:1.0"

Documentation Source

Summary

Provides simple, free, UK postcode to lat/lon lookups and distance calculations.

Description

This plugin is a little old now. It probably still works fine but the data may be a little out of date.

This plugin provides a single artefact, the PostCodeService. This lets you look up a UK postcode string and retrieve the lat/lon coordinates for the "centre of the postcode sector". The data is free, from http://www.nearby.org.uk, and has over 10,000 postcode centre points defined. It may however not be complete, and currently operates at the postcode sector level, not street level.

You can also retrieve the distance between two postcodes, or two lat/lon points, so that you can perform proximity searches etc on UK data without having to use a geocoding service such as Google Maps API.

Usage:

class LocalSearchController {
   def postCodeService

def findByPostcodeWithin10km = { def userLocation = postCodeService.getPostCodeCentre(params.postCode) assert userLocation, "Ooops postcode not found in DB"

model.result = [] BookShop.list().each() { shop -> def location = postCodeService.getPostCodeCentre(shop.postCode) def distInKM = postCodeService.getDistanceBetweenPoints(userLocation.centre, location.centre) // Is it within 10km? if (distInKM < 10) model.results << shop } render(view:"results", model:model) }

def getDistanceBetweenPostCodes = { def d = postCodeService.getDistanceBetweenPostCodes(params.postCodeA, params.postCodeB) render(view:"distanceResult", model:[distance: d]) } }