geo static method
Discover the precise physical location of a given IP address, the default geo search is from this device current Public IP address.
Returns a result of type GeoModel which is a generated class.
This require an apiKey from https://geo.ipify.org/
Usage:
final mygeo = Ipify.geo('apiKey');
print(mygeo.location.country); // TN
final somegeo = Ipify.geo('apiKey', ip: '8.8.8.8');
print(somegeo.toJson());
{
"ip": "8.8.8.8",
"location": {
"country": "US",
"region": "California",
"city": "Mountain View",
"lat": 37.4223,
"lng": -122.085,
"postalCode": "94043",
"timezone": "-07:00",
"geonameId": 5375480
},
"domains": [
"0--9.ru",
"000.lyxhwy.xyz",
"000180.top",
"00049ok.com",
"001998.com.he2.aqb.so"
],
"as": {
"asn": 15169,
"name": "Google LLC",
"route": "8.8.8.0/24",
"domain": "https://about.google/intl/en/",
"type": "Content"
},
"isp": "Google LLC",
"proxy": {
"proxy": false,
"vpn": false,
"tor": false
}
}
Implementation
static Future<GeoModel> geo(String api, {String? ip}) async {
ip ??= await ipv4();
final query = 'apiKey=$api&ipAddress=$ip';
final uri =
Uri(host: _geoHost, path: _geoPath, scheme: _scheme, query: query);
final response = await _send(uri);
return GeoModel.fromJson(response);
}