Sample code for 30+ languages & platforms
React Native

ipapi.co IPv4 Geolocation Lookup

See more Geolocation Examples

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

Chilkat React Native Downloads

React Native
import { Http, JsonObject } from '@chilkat/react-native'

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

  const http = new Http();

  // Lookup an IPv4 address: 149.250.207.170  (this was a randomly chosen address)
  let jsonStr: string;
  try {
    jsonStr = await http.quickGetStrAsync('https://ipapi.co/149.250.207.170/json');
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  const json = new JsonObject();
  json.emitCompact = false;
  json.load(jsonStr);

  console.log(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",
  //   "city": "B�blingen",
  //   "region": "Baden-W�rttemberg",
  //   "region_code": null,
  //   "country": "DE",
  //   "country_name": "Germany",
  //   "continent_code": "EU",
  //   "in_eu": true,
  //   "postal": null,
  //   "latitude": null,
  //   "longitude": null,
  //   "timezone": null,
  //   "utc_offset": null,
  //   "country_calling_code": "+49",
  //   "currency": "EUR",
  //   "languages": "de",
  //   "asn": "AS15854",
  //   "org": "EntServ Deutschland GmbH"
  // }

  const ip = json.stringOf('ip');
  const city = json.stringOf('city');
  const region = json.stringOf('region');
  const regionCode = json.stringOf('region_code');
  const country = json.stringOf('country');
  const countryName = json.stringOf('country_name');
  const continentCode = json.stringOf('continent_code');
  const postal = json.stringOf('postal');
  const latitude = json.stringOf('latitude');
  const longitude = json.stringOf('longitude');
  const timezone = json.stringOf('timezone');
  const utcOffset = json.stringOf('utc_offset');
  const countryCallingCode = json.stringOf('country_calling_code');
  const currency = json.stringOf('currency');
  const languages = json.stringOf('languages');
  const asn = json.stringOf('asn');
  const org = json.stringOf('org');
}