Script to determine user location

Using third party API provided by https://ipinfo.io/ to determine IP, country, Latitude/Longitude of user.

This may be used to display certain content to a user based on their location, or could be used to redirect them to another page (more appropriate for their location).

Sample code:

<script>
    $.get("https://ipinfo.io", function (response) {
        $("#ip").html("IP: " + response.ip);
        $("#address").html("Location: " + response.city + ", " + response.region);
        $("#details").html(JSON.stringify(response, null, 4));
    }, "jsonp");
</script>
<div id="ip"></div>
<div id="address"></div>
<hr/>Full response: <pre id="details"></pre>

Another example that appends au/nz based on user's country to the link.

<script>
	$(function() {
		$.get("https://ipinfo.io", function (response) {
		    $('.homepage a[href]').attr('href', function(index, href) {
		    	country_code = 'au';
		    	if(response.country == 'NZ') {
		    		country_code = 'nz';
		    	}
		        var param = country_code;

		        if (href.charAt(href.length - 1) === '?') //Very unlikely
		            return href + param;
		        else if (href.indexOf('?') > 0)
		            return href + '/' + param;
		        else
		            return href + '/' + param;
		    });
		}, "jsonp");
	    
	})
</script>