Grails GeoIP (MaxMind) Integration

  • Authors : null
2 votes
Dependency :
compile ":geoip:0.2"

Documentation

Summary

Installation

grails install-plugin geoip

Description

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:

1) You must configure 2 properties in your Config.groovy:

  • Path to your Maxmind database file. You can get a free Lite version here: http://www.maxmind.com/app/geolitecity. You must define one of the following:
    • geoip.data.path = "/opt/geoip/GeoLiteCity.dat" - The path to the database on the file system ]
    • geoip.data.resource= "/WEB-INF/GeoLiteCity.dat" - The path to the database, which is bundled as a resource in the war file ]
  • geoip.data.cache - There are 4 possible values for this:
    • 0 - GEOIP_STANDARD
    • 1 - GEOIP_MEMORY_CACHE
    • 2 - GEOIP_CHECK_CACHE
    • 4 - GEOIP_INDEX_CACHE
Note that when you're using the cached versions it will load the database in memory. Its size is usually around 45 MB.
2) At the moment the service exposes only one method. Here is how you determine the location of an IP:
class MyController {
        def geoIpService
        def index = {
            def location = geoIpService.getLocation("88.158.9.150")
            render location.countryName + " " + location.city
        }
    }

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
  • regionName
  • city
  • postalCode
  • timezone
  • latitude
  • longitude
  • dmaCode
  • areaCode
  • metroCode