Geolocation API

The Geolocation API provides real-time look up of geographical locations using IP addresses.

Get location by IP

public static IPLocation get(final String ip, final String fields, final Boolean hostname, final Boolean security)

Looks up geolocation for an IP address.

Arguments

Argument Type Description Required
ip String The IP address or domain name to look up. Yes
fields String Comma separated list of fields to return to the caller. No
hostname Boolean Look up host name from IP address. No
security Boolean Return extended security information about the IP address. No

Returns

This call returns an IPLocation object, and throws an APIException otherwise.

Example

package examples;

import com.objectia.ObjectiaClient;
import com.objectia.api.GeoLocation;
import com.objectia.exceptions.APIException;
import com.objectia.exceptions.ResponseException;
import com.objectia.models.IPLocation;

public class Example {
    public static void main(String[] args) {
        String apiKey = System.getenv("OBJECTIA_APIKEY");

        try {
            ObjectiaClient.init(apiKey);
            IPLocation location = GeoLocation.get("8.8.8.8");
            System.out.println("Country code: " + location.getCountryCode());
        } catch (ResponseException e) {
            System.err.println("Response error: " + e.getMessage());
        } catch (APIException e) {
            System.err.println("API error: " + e.getMessage());
        } catch (IllegalArgumentException e) {
            System.err.println("Error: " + e.getMessage());
        }
    }
}

Get location of multiple IP addresses

public static List<IPLocation> getBulk(final String ipList[])

public static List<IPLocation> getBulk(final String ipList[], final String fields, final Boolean hostname, final Boolean security)

Looks up geolocation for multiple IP addresses.

Arguments

Argument Type Description Required
ipList String[] Array of strings with the IP addresses or domain names to look up. Yes
fields String Comma separated list of fields to return to the caller. No
hostname Boolean Look up host name from IP address. No
security Boolean Return extended security information about the IP address. No

Returns

This call returns a list of IPLocation objects, and throws an APIException otherwise.

Example

package examples;

import com.objectia.ObjectiaClient;
import com.objectia.api.GeoLocation;
import com.objectia.exceptions.APIException;
import com.objectia.exceptions.ResponseException;
import com.objectia.models.IPLocation;

public class Example {
    public static void main(String[] args) {
        String apiKey = System.getenv("OBJECTIA_APIKEY");

        try {
            ObjectiaClient.init(apiKey);
            List<IPLocation> locations = GeoLocation.getBulk(new String[]{"8.8.8.8", "google.com"});
            for (IPLocation l : locations) {
                System.out.println("Country code: " + l.getCountryCode());
            }
        } catch (ResponseException e) {
            System.err.println("Response error: " + e.getMessage());
        } catch (APIException e) {
            System.err.println("API error: " + e.getMessage());
        } catch (IllegalArgumentException e) {
            System.err.println("Error: " + e.getMessage());
        }
    }
}

Get location of caller

public static IPLocation getCurrent()

public static IPLocation getCurrent(final String fields, final Boolean hostname, final Boolean security)

Gets geolocation of caller's current IP address.

Arguments

Argument Type Description Required
fields String Comma separated list of fields to return to the caller. No
hostname Boolean Look up host name from IP address. No
security Boolean Return extended security information about the IP address. No

Arguments

This call returns an IPLocation object, and throws an APIException otherwise.

Example

package examples;

import com.objectia.ObjectiaClient;
import com.objectia.api.GeoLocation;
import com.objectia.exceptions.APIException;
import com.objectia.exceptions.ResponseException;
import com.objectia.models.IPLocation;

public class Example {
    public static void main(String[] args) {
        String apiKey = System.getenv("OBJECTIA_APIKEY");

        try {
            ObjectiaClient.init(apiKey);
            IPLocation location = GeoLocation.getCurrent();
            System.out.println("Country code: " + location.getCountryCode());
        } catch (ResponseException e) {
            System.err.println("Response error: " + e.getMessage());
        } catch (APIException e) {
            System.err.println("API error: " + e.getMessage());
        } catch (IllegalArgumentException e) {
            System.err.println("Error: " + e.getMessage());
        }
    }
}