Grails GeoIP Plugin (based on MaxMind library)
This plugin facilitates grails integration with the opensource GeoIP framework offered by MaxMind. Using its straightforward API one can find out the country, area, city, geographical coordinates and others based on an IP.
Add the following plugin definition to your BuildConfig:
…
plugins {
…
compile ':geoip:0.3.3'
…
}
Then run script to download and install free GeoLite database:
grails install-geo-data
The plugin adds a dynamic method to your controllers to determine location of client is accessing the app:
isInCountry(String countryCode) (where countryCode
is ISO 3166 Country Code) will be true if the client use IP from this country.
def list() {
...
if (isInCountry('US')) {
render(view: 'usa')
} else {
render(view: 'default')
}
}
Additionally, you can run code conditionally, with access to the current com.maxmind.geoip.Location
instance, with this method:
withLocation(Closure closure)
def list() {
...
def view = 'list'
withLocation { location ->
view = "list_${location.countryCode}"
}
render(view: view, model: [list: listInstance])
}
Copyright 2009-2013 Radu Andrei Tanasa, Alexey Zhokhov under the GNU Lesser General Public License, version 2.1. Supported by AZ.
This product includes GeoLite data created by MaxMind, available from www.maxmind.com.