Sample code for 30+ languages & platforms
React Native

ip-api.com IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the ip-api.com 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('http://ip-api.com/json/149.250.207.170');
  } 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

  // {
  //   "as": "AS15854 Hewlett Packard GmbH",
  //   "city": "B�blingen",
  //   "country": "Germany",
  //   "countryCode": "DE",
  //   "isp": "Triaton Frankfurt",
  //   "lat": 48.6779,
  //   "lon": 8.97297,
  //   "org": "EntServ Deutschland GmbH",
  //   "query": "149.250.207.170",
  //   "region": "BW",
  //   "regionName": "Baden-W�rttemberg",
  //   "status": "success",
  //   "timezone": "Europe/Berlin",
  //   "zip": "71034"
  // }

  const asArg = json.stringOf('as');
  const city = json.stringOf('city');
  const country = json.stringOf('country');
  const countryCode = json.stringOf('countryCode');
  const isp = json.stringOf('isp');
  const lat = json.stringOf('lat');
  const lon = json.stringOf('lon');
  const org = json.stringOf('org');
  const query = json.stringOf('query');
  const region = json.stringOf('region');
  const regionName = json.stringOf('regionName');
  const status = json.stringOf('status');
  const timezone = json.stringOf('timezone');
  const zip = json.stringOf('zip');
}