Sample code for 30+ languages & platforms
Java

ipdata.co IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the ipdata.co API.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.JsonObject;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

        String jsonStr;
        try {
            jsonStr = http.quickGetStr("https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        JsonObject json = new JsonObject();
        json.setEmitCompact(false);
        json.load(jsonStr);

        System.out.println(json.emit());

        // Sample output:
        // Use this online tool to generate parsing code from sample JSON:
        // Generate Parsing Code from JSON

        // {
        //   "ip": "149.250.207.170",
        //   "is_eu": true,
        //   "city": null,
        //   "region": null,
        //   "region_code": null,
        //   "country_name": "Germany",
        //   "country_code": "DE",
        //   "continent_name": "Europe",
        //   "continent_code": "EU",
        //   "latitude": 51.2993,
        //   "longitude": 9.491,
        //   "asn": "AS15854",
        //   "organisation": "EntServ Deutschland GmbH",
        //   "postal": null,
        //   "calling_code": "49",
        //   "flag": "https://ipdata.co/flags/de.png",
        //   "emoji_flag": "\ud83c\udde9\ud83c\uddea",
        //   "emoji_unicode": "U+1F1E9 U+1F1EA",
        //   "languages": [
        //     {
        //       "name": "German",
        //       "native": "Deutsch"
        //     }
        //   ],
        //   "currency": {
        //     "name": "Euro",
        //     "code": "EUR",
        //     "symbol": "\u20ac",
        //     "native": "\u20ac",
        //     "plural": "euros"
        //   },
        //   "time_zone": {
        //     "name": "Europe/Berlin",
        //     "abbr": "CEST",
        //     "offset": "+0200",
        //     "is_dst": true,
        //     "current_time": "2019-04-20T23:54:30.715507+02:00"
        //   },
        //   "threat": {
        //     "is_tor": false,
        //     "is_proxy": false,
        //     "is_anonymous": false,
        //     "is_known_attacker": false,
        //     "is_known_abuser": false,
        //     "is_threat": false,
        //     "is_bogon": false
        //   },
        //   "count": "2"
        // }

        String name = "";
        String native_ = "";

        String ip = json.stringOf("ip");
        boolean is_eu = json.boolOf("is_eu");
        String city = json.stringOf("city");
        String region = json.stringOf("region");
        String region_code = json.stringOf("region_code");
        String country_name = json.stringOf("country_name");
        String country_code = json.stringOf("country_code");
        String continent_name = json.stringOf("continent_name");
        String continent_code = json.stringOf("continent_code");
        String latitude = json.stringOf("latitude");
        String longitude = json.stringOf("longitude");
        String asn = json.stringOf("asn");
        String organisation = json.stringOf("organisation");
        String postal = json.stringOf("postal");
        String calling_code = json.stringOf("calling_code");
        String flag = json.stringOf("flag");
        String emoji_flag = json.stringOf("emoji_flag");
        String emoji_unicode = json.stringOf("emoji_unicode");
        String currencyName = json.stringOf("currency.name");
        String currencyCode = json.stringOf("currency.code");
        String currencySymbol = json.stringOf("currency.symbol");
        String currencyNative = json.stringOf("currency.native");
        String currencyPlural = json.stringOf("currency.plural");
        String time_zoneName = json.stringOf("time_zone.name");
        String time_zoneAbbr = json.stringOf("time_zone.abbr");
        String time_zoneOffset = json.stringOf("time_zone.offset");
        boolean time_zoneIs_dst = json.boolOf("time_zone.is_dst");
        String time_zoneCurrent_time = json.stringOf("time_zone.current_time");
        boolean threatIs_tor = json.boolOf("threat.is_tor");
        boolean threatIs_proxy = json.boolOf("threat.is_proxy");
        boolean threatIs_anonymous = json.boolOf("threat.is_anonymous");
        boolean threatIs_known_attacker = json.boolOf("threat.is_known_attacker");
        boolean threatIs_known_abuser = json.boolOf("threat.is_known_abuser");
        boolean threatIs_threat = json.boolOf("threat.is_threat");
        boolean threatIs_bogon = json.boolOf("threat.is_bogon");
        String count = json.stringOf("count");
        int i = 0;
        int count_i = json.sizeOfArray("languages");
        while (i < count_i) {
            json.setI(i);
            name = json.stringOf("languages[i].name");
            native_ = json.stringOf("languages[i].native");
            i = i + 1;
        }
    }
}