Depends where you store the data.
There's a free and very simple API site to get geolocation details from IP's, at
http://hostip.info
So a calc element (with "Only calc on save" set to yes) with something like ...
Code:
return file_get_contents('https://api.hostip.info/country.php?ip={yourtable___your_ip_element');
... should do it.
You can also get the city, although this is of very limited use. For instance, my IP shows as being in Vallejo, CA ... about 2,000 miles away:
{"country_name":"UNITED STATES","country_code":"US","city":"Vallejo, CA","ip":"75.76.15.183"}
For that you need to get the JSON ...
Code:
$hostinfo = file_get_contents('https://api.hostip.info/get_json.php?ip={yourtable___your_ip_element');
$hostinfo = json_decode($hostinfo);
return $hostinfo->city;
If you are filling multiple fields, I'd recommend a PHP form submission script (running onBeforeProcess) rather than individual calc's calling the API multiple times, and using $formModel->updateFormData('yourtable___whatever', $whatever, true) to set each value.
-- hugh