Userinfo.io

Get the IP & geolocation info of your users.

Get your users' location: latitude, longitude and accuracy.
Resolve the location to get the country or city of your users.
Userinfo.io finds your users' IP address in a breeze.
Userinfo.io is completely free, without any restriction.
Integrate one of our libraries in seconds.
No server nor heavy backend is needed, we do that for you.

Integrate userinfo.io

Add the javascript library to your page

Get the library on CDNJS or download it and insert the following code between the <head> and </head> tags of your page:

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/userinfo/1.1.0/userinfo.min.js"></script>

You can also use it as an AMD module. More details are on Github.

If needed, you can directly call the API with a JSONP callback or a JSONP variable. See this gist for an example.

Get your user's info

Anywhere in your code, use the library to get the info you need:

<script type="text/javascript">
UserInfo.getInfo(function(data) {
  // the "data" object contains the info
}, function(err) {
  // the "err" object contains useful information in case of an error
});
</script>

The information retrieval is asynchronous so it will not block your javascript thread.

The "info" object

Here is a example of a response you can receive:

{
  request_date: "2014-09-18T04:11:25.154Z",
  ip_address: "192.77.237.95",
  position: {
    latitude: 37.7758,
    longitude: -122.4128,
    accuracy: 3   // This is the accuracy radius, in kilometers
  },
  continent: {
    name: "North America",
    code: "NA",
  },
  country: {
    name: "United States",
    code: "US",
  },
  city: {
    name: "San Francisco",
    code: "94103"
  }
}

Be sure to check if the fields have a value: if we can't resolve an ip, we won't consider it as an error and will send back an object with null values.

Add the java library to your dependencies

Add the library to your pom or download it:

<dependency>
  <groupId>io.userinfo</groupId>
  <artifactId>userinfo-java</artifactId>
  <version>1.1.0</version>
</dependency>

More details on Github.

Get your user's info

Anywhere in your code, use the library to get the info you need:

String ipAddress = "192.77.237.95"; // your user's IP
Info info = UserInfo.getInfo(ipAddress);
System.out.println(info);

To get the IP address of an incoming request on a servlet, you can use the method javax.servlet.ServletRequest#getRemoteAddr.

The "Info" object

Here is the API of the object you will receive:

  • Info.class
    • DateTime getRequestDate(): returns the request date
    • DateTime getRequestDate(): returns the request date
    • String getIpAddress(): returns the IP address
    • Position getPosition(): returns the position of the user
    • Place getContinent(): returns the place defining the continent
    • Place getCountry(): returns the place defining the country
    • Place getCity(): returns the place defining the city
  • Position.class
    • Double getLatitude(): the latitude
    • Double getLongitude(): the longitude
    • Double getAccuracy(): the accuracy (in km)
  • Place.class
    • String getName(): the name of the place
    • String getCode(): the international code of the place (for a city, it will be the postal code)

Be sure to check if the results have a value: if we can't resolve an ip, we won't consider it as an error and will send back an object with null values.

Commands

You can easily issue a request to the REST API using curl.

Get you own information:

curl https://api.userinfo.io/userinfos

Get information on a specific IP address:

curl https://api.userinfo.io/userinfos?ip_address=192.77.237.95

The "info" object

Here is a example of a response you can receive:

{
  request_date: "2014-09-18T04:11:25.154Z",
  ip_address: "192.77.237.95",
  position: {
    latitude: 37.7758,
    longitude: -122.4128,
    accuracy: 3   // This is the accuracy radius, in kilometers
  },
  continent: {
    name: "North America",
    code: "NA",
  },
  country: {
    name: "United States",
    code: "US",
  },
  city: {
    name: "San Francisco",
    code: "94103"
  }
}

XML Formatting

You can also request an XML formatting of the response:

curl https://api.userinfo.io/userinfos.xml

or:

curl https://api.userinfo.io/userinfos.xml?ip_address=192.77.237.95

The response will then look like:

<userinfo>
  <requestDate>2014-09-18T04:11:25.154Z</requestDate>
  <ipAddress>192.77.237.95</ipAddress>
  <position>
    <latitude>37.7758</latitude>
    <longitude>-122.4128</longitude>
    <accuracy>3</accuracy>   <!-- This is the accuracy radius, in kilometers -->
  </position>
  <continent>
    <name>North America</name>
    <code>NA</code>
  </continent>
  <country>
    <name>United States</name>
    <code>US</code>
  </country>
  <city>
    <name>San Francisco</name>
    <code>94103</code>
  </city>
</userinfo>

Other languages

If you need a library that is not available yet, let us know at hello@userinfo.io, we'll probably have the time to build it for you!

Accuracy

The vendors we use at userinfo.io provide us with the best quality of information possible. However, since there is no official and complete database of IP geolocation, there is currently no way to get 100% accurate data.

Here an estimate of the geolocation accuracy:

Usually, those results are satisfying to get an idea of a user's origin. It should not be used if the location is sensitive since we can't be sure of the exact position of the end-user.

As a rule of thumb, the results are pretty accurate in the most developped countries.

Support

If you have any problem with the service, drop us a line at hello@userinfo.io