Member-only story

Spring boot geolocation by IP using GeoLite2 database.

Eric Anicet
3 min readSep 14, 2020

--

In this story, we will show how to get user information (devices, country, city, latitude, longitude) using an IP address.

In a production application, it is important as a user to check which computers, phones, and other devices have recently used your account, to ensure that no one other than you has signed into your account. To improve security, the user must be able to know the geographical position of the equipment which has used his account in order to be able to delete the connections on them in the event that the connections do not come from him.

In this article, we will explore how to get geographic location data from an IP address using the MaxMind GeoIP2 Java API with the free GeoLite2 database.

GeoLite2 Databases

GeoLite2 databases are free IP geolocation databases comparable to, but less accurate than, MaxMind’s GeoIP2 databases. The GeoLite2 Country, City, and ASN databases are updated weekly, every Tuesday. GeoIP2 supports for many different programming languages such as: .NET (C#), C, Java, Node.js, Ruby, PHP, Python, …

There are two way to work with GeoIP2 API:

  • Download GeoLite2 with location data and use it as a local database. GeoIP2 API will retrieve geographic information from this database.

--

--

Responses (2)