Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = CkHttp();

  final String jsonStr;
  try {
    jsonStr = http.quickGetStr('https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final json = CkJsonObject();
  json.emitCompact = false;
  json.load(jsonStr);

  print(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"
  // }

  var i = 0;
  var name = '';
  var native = '';

  final ip = json.stringOf('ip');
  final city = json.stringOf('city');
  final region = json.stringOf('region');
  final regionCode = json.stringOf('region_code');
  final countryName = json.stringOf('country_name');
  final countryCode = json.stringOf('country_code');
  final continentName = json.stringOf('continent_name');
  final continentCode = json.stringOf('continent_code');
  final latitude = json.stringOf('latitude');
  final longitude = json.stringOf('longitude');
  final asn = json.stringOf('asn');
  final organisation = json.stringOf('organisation');
  final postal = json.stringOf('postal');
  final callingCode = json.stringOf('calling_code');
  final flag = json.stringOf('flag');
  final emojiFlag = json.stringOf('emoji_flag');
  final emojiUnicode = json.stringOf('emoji_unicode');
  final currencyName = json.stringOf('currency.name');
  final currencyCode = json.stringOf('currency.code');
  final currencySymbol = json.stringOf('currency.symbol');
  final currencyNative = json.stringOf('currency.native');
  final currencyPlural = json.stringOf('currency.plural');
  final timeZoneName = json.stringOf('time_zone.name');
  final timeZoneAbbr = json.stringOf('time_zone.abbr');
  final timeZoneOffset = json.stringOf('time_zone.offset');
  final timeZoneCurrentTime = json.stringOf('time_zone.current_time');
  final count = json.stringOf('count');
  i = 0;
  final countI = json.sizeOfArray('languages');
  while (i < countI) {
    json.i = i;
    name = json.stringOf('languages[i].name');
    native = json.stringOf('languages[i].native');
    i++;
  }
}