Grails GeoIP Plugin

  • Authors : Radu Andrei Tanasa, Alexey Zhokhov, Alexey Zhokhov
3 votes
Dependency :
compile ":geoip:0.3.1"

Documentation Source Issues

Summary

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.This product includes GeoLite data created by MaxMind, available fromwww.maxmind.com.

Installation

Add the following to your grails-app/conf/BuildConfig
…
plugins {
…
	compile ':geoip:0.3.1'
…
}

Then run following command to download GeoLite database from MaxMind website

grails install-geo-data

Description

Introduction

The purpose of this very simple plugin is to provide a seemless integration with MaxMind's geographical location open source API and has been built to be used with the GeoCity binary database.

Usage

The plugin adds dynamic methods to your controllers to determine location of client is accessing the app:

isInXXX() (where XXX is ISO 3166 Country Code) will be true if the client use IP from this country.

def list() {
    …
    if (isInUS()) {
        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])
}

Here is a list of the Location's fields.

Note that some may not be properly populated if the information is missing.
  • countryCode
  • countryName
  • region
  • city
  • postalCode
  • latitude
  • longitude
  • dma_code
  • area_code
  • metro_code

Copyright and license

Copyright 2009-2013 Radu Andrei Tanasa, Alexey Zhokhov under the GNU Lesser General Public License, version 2.1.

This product includes GeoLite data created by MaxMind, available from www.maxmind.com.