jQuery: detect user’s country

 Posted on 15 December 2011

A method that is is so simple that can be used to detect the country (no need to use php to find out your ip) of the user who is entering our site is using the API of wipmania via jQuery. The query method returns to us a few parameters such as latitude, longitude, zoom, address, city, country, the country code, region.

If we introduce directly in our browser the url “http://api.wipmania.com/jsonp?callback =?” And we look at the data returned. You only need to use JSON to retrieve with jQuery as follows:

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) {
  alert('País: ' + data.address.country);
});
</script>

Incoming search terms:

  • jquery detect country
  • detect country jquery
  • jquery get user country
  • jquery to detect browser country
  • jquery country detection
  • get user country jquery
  • jquery get users country
Share with your friends!
Published by admin in How To

1 comment

  1. Perla says:

    This doesn’t work, update the post please, i need to detect country

Write a comment

YES you can use HTML code in comments.
NO you cannot leave spam or insult anyone.

Your coment will be moderated the first time. Later on it will not be moderated as long as you use the same contact info.