How to get the Country from an IP address

Getting the Country

This example shows you how to get the country, city and region from an IP address.


// The API returns the ISO ALPHA-2 Country Code and the Country Name

<pre id="response">
    <div id="country_name"></div>
    <div id="country_code"></div>
    <div id="city"></div>
    <div id="region"></div>
</pre>

// Getting the country code and name from the user's IP
$.get("https://api.ipdata.co", function (response) {
    $("#country_name").html('Country Name: ' + response.country_name);
    $("#country_code").html('Country Code: ' + response.country_code);
    $("#city").html('City: ' + response.city);
    $("#region").html('region: ' + response.region);
}, "jsonp");