Plugins You can find out about all the publicly available Grails plugins.


  • Authors: Marc Palmer
0 vote
compile "org.grails.plugins:post-code:1.0"

 Documentation  Source


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


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


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]) } }