Professional Documents
Culture Documents
Get Location by Ip
Get Location by Ip
Futur<String> getCountryNameByIP();
How it works ?
1
apiip API returns more than 40 unique data
points, such as location data, and that what we
2
need.
in the function body we test if the country
to use this service,we have to get the ip Name is stored in Storage using
address of the device and the accessKey and FlutterSecureStorage, if its then return the
the put them in a url like this: stored data ,
http://apiip.net/api/check?ip=67.250.186.196
&accessKey=ef7b5d33-cbff-4a3e-841f-c414a72fb3c0 If not ,then we call the uri and get a
response,
Check the response status if its successfully
the key we put it in the global variables connected (status code = 200 ) then get then
accessKey=« ef7b5d33-cbff-4a3e-841f- decode the response body to get the country
c414a72fb3c0 »;
Name and store it in storage , else throw an
exception,
and the ip address we get it using this url:
'https://api.ipify.org'
Example of response
{
"ip": "67.250.186.196",
"continentCode": "NA",
"continentName": "North America",
"countryCode": "US",
"countryName": "United States",
"countryNameNative": "United States",
"officialCountryName": "United States of America",
"regionCode": "NY",
"regionName": "New York",
"cityGeoNameId": 5128581,
"city": "New York",
"postalCode": "10004",
"latitude": 40.7123,
"longitude": -74.0068,
"capital": "Washington D.C.",
"phoneCode": "1",
"countryFlagEmoj": "🇺🇸 ",
"countryFlagEmojUnicode": "U+1F1FA U+1F1F8",
"borders": [
"CAN",
"MEX"
],
"topLevelDomains": [
".us"
]
}
Example of function