Sample code for 30+ languages & platforms
React Native

api.db-ip.com IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the api.db-ip.com 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('http://api.db-ip.com/v2/free/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

  // {
  //   "ipAddress": "149.250.207.170",
  //   "continentCode": "EU",
  //   "continentName": "Europe",
  //   "countryCode": "DE",
  //   "countryName": "Germany",
  //   "stateProv": "Baden-W\u00fcrttemberg",
  //   "city": "B\u00f6blingen"
  // }

  const ipAddress = json.stringOf('ipAddress');
  const continentCode = json.stringOf('continentCode');
  const continentName = json.stringOf('continentName');
  const countryCode = json.stringOf('countryCode');
  const countryName = json.stringOf('countryName');
  const stateProv = json.stringOf('stateProv');
  const city = json.stringOf('city');
}