React Native
React Native
MaxMind IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the MaxMind GeoIP2 Precision Web Service.Chilkat React Native Downloads
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();
http.login = 'MAXMIND_ACCOUNT_ID';
http.password = 'MAXMIND_LICENSE_KEY';
http.accept = 'application/json';
// Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address)
let jsonStr: string;
try {
jsonStr = await http.quickGetStrAsync('https://geoip.maxmind.com/geoip/v2.1/country/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
// {
// "continent": {
// "code": "EU",
// "geoname_id": 6255148,
// "names": {
// "ja": "?????",
// "pt-BR": "Europa",
// "ru": "??????",
// "zh-CN": "??",
// "de": "Europa",
// "en": "Europe",
// "es": "Europa",
// "fr": "Europe"
// }
// },
// "country": {
// "is_in_european_union": true,
// "iso_code": "DE",
// "geoname_id": 2921044,
// "names": {
// "fr": "Allemagne",
// "ja": "????????",
// "pt-BR": "Alemanha",
// "ru": "????????",
// "zh-CN": "??",
// "de": "Deutschland",
// "en": "Germany",
// "es": "Alemania"
// }
// },
// "maxmind": {
// "queries_remaining": 49999
// },
// "registered_country": {
// "is_in_european_union": true,
// "iso_code": "DE",
// "geoname_id": 2921044,
// "names": {
// "es": "Alemania",
// "fr": "Allemagne",
// "ja": "????????",
// "pt-BR": "Alemanha",
// "ru": "????????",
// "zh-CN": "??",
// "de": "Deutschland",
// "en": "Germany"
// }
// },
// "traits": {
// "ip_address": "149.250.207.170"
// }
// }
//
//
const continentCode = json.stringOf('continent.code');
const continentGeonameId = json.intOf('continent.geoname_id');
const continentNamesJa = json.stringOf('continent.names.ja');
const continentNamesPtBR = json.stringOf('continent.names.pt-BR');
const continentNamesRu = json.stringOf('continent.names.ru');
const continentNamesZhCN = json.stringOf('continent.names.zh-CN');
const continentNamesDe = json.stringOf('continent.names.de');
const continentNamesEn = json.stringOf('continent.names.en');
const continentNamesEs = json.stringOf('continent.names.es');
const continentNamesFr = json.stringOf('continent.names.fr');
const countryIsoCode = json.stringOf('country.iso_code');
const countryGeonameId = json.intOf('country.geoname_id');
const countryNamesFr = json.stringOf('country.names.fr');
const countryNamesJa = json.stringOf('country.names.ja');
const countryNamesPtBR = json.stringOf('country.names.pt-BR');
const countryNamesRu = json.stringOf('country.names.ru');
const countryNamesZhCN = json.stringOf('country.names.zh-CN');
const countryNamesDe = json.stringOf('country.names.de');
const countryNamesEn = json.stringOf('country.names.en');
const countryNamesEs = json.stringOf('country.names.es');
const maxmindQueriesRemaining = json.intOf('maxmind.queries_remaining');
const registeredCountryIsoCode = json.stringOf('registered_country.iso_code');
const registeredCountryGeonameId = json.intOf('registered_country.geoname_id');
const registeredCountryNamesEs = json.stringOf('registered_country.names.es');
const registeredCountryNamesFr = json.stringOf('registered_country.names.fr');
const registeredCountryNamesJa = json.stringOf('registered_country.names.ja');
const registeredCountryNamesPtBR = json.stringOf('registered_country.names.pt-BR');
const registeredCountryNamesRu = json.stringOf('registered_country.names.ru');
const registeredCountryNamesZhCN = json.stringOf('registered_country.names.zh-CN');
const registeredCountryNamesDe = json.stringOf('registered_country.names.de');
const registeredCountryNamesEn = json.stringOf('registered_country.names.en');
const traitsIpAddress = json.stringOf('traits.ip_address');
}