You shouldn't use an API when you already have existing data on your machine to do this.
you can use apache2's mod_geoip (apt-get install apache2-mod-geoip or yum install mod_geoip.x86_64)
then, restart apache2. and now
It worked like a charm for me.
$country_name = apache_note("GEOIP_COUNTRY_NAME");
print "Country: " . $country_name;
Country: United States
I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;