geoPlugin

A snippet of jQuery code that calls the geoplugin.net service to retrieve geo location data for the current IP.

HTML

<div id="output"></div>

CSS

#output {font-size: 20px;}

JavaScript

$.getJSON("http://www.geoplugin.net/json.gp?jsoncallback=?&ip=94.55.245.89", function(data) {
    
    var o = "",
        i;
    
    // List all returned values
    for (i in data) {
        if (data.hasOwnProperty(i)) {
            o += i + ': ' + data[i] + '<br>';
        }
    }
    
    // Get value by hardcoded name
    o += data.geoplugin_city + '<br>';
    
    $("#output").html(o);
    
    
});