Dart
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final http = CkHttp();
// Lookup an IPv4 address: 8.8.8.8
final String jsonStr;
try {
jsonStr = http.quickGetStr('https://geo.ipify.org/api/v1?apiKey=API_KEY&ipAddress=8.8.8.8');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final json = CkJsonObject();
json.emitCompact = false;
json.load(jsonStr);
print(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"
// }
// }
final ip = json.stringOf('ip');
final locationCountry = json.stringOf('location.country');
final locationRegion = json.stringOf('location.region');
final locationCity = json.stringOf('location.city');
final locationLat = json.stringOf('location.lat');
final locationLng = json.stringOf('location.lng');
final locationPostalCode = json.stringOf('location.postalCode');
final locationTimezone = json.stringOf('location.timezone');
}