How to get the Country Flag from an IP address

Getting the Flag

This example shows you how to get the country flag from an IP address.


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

<div id="country-name"></div>
<br>
<div id="emoji-flag"></div>
<br>
<img src=""id="img-flag">


// Getting the country code and name from the user's IP
$.get("https://api.ipdata.co", function (response) {
		$("#country-name").html(response.country_name);
    $("#emoji-flag").html(response.emoji_flag);
    $("#img-flag").attr('src',response.flag);
}, "jsonp");