React Native
React Native
geo.ipify.org IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the geo.ipify.org REST API.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();
// Lookup an IPv4 address: 8.8.8.8
let jsonStr: string;
try {
jsonStr = await http.quickGetStrAsync('https://geo.ipify.org/api/v1?apiKey=API_KEY&ipAddress=8.8.8.8');
} 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": "8.8.8.8",
// "location": {
// "country": "IT",
// "region": "Lombardy",
// "city": "Milan",
// "lat": 45.4707,
// "lng": 9.1889,
// "postalCode": "20147",
// "timezone": "+02:00"
// }
// }
const ip = json.stringOf('ip');
const locationCountry = json.stringOf('location.country');
const locationRegion = json.stringOf('location.region');
const locationCity = json.stringOf('location.city');
const locationLat = json.stringOf('location.lat');
const locationLng = json.stringOf('location.lng');
const locationPostalCode = json.stringOf('location.postalCode');
const locationTimezone = json.stringOf('location.timezone');
}