JSON Web Service
The JSON web service allows you to directly program your back-end JSON scripts to deliver dynamic geo-localized pages using the JSON variables provided by geoPlugin.
To access this service, add the following url to a remote include call
http://www.geoplugin.net/json.gp?ip=xx.xx.xx.xx
Of course, substitute the xx's with your visitor's IP number.
Example output of a JSON query for your IP address (38.107.191.113) is:
geoPlugin({
"geoplugin_city":"",
"geoplugin_region":"",
"geoplugin_areaCode":"0",
"geoplugin_dmaCode":"0",
"geoplugin_countryCode":"US",
"geoplugin_countryName":"United States",
"geoplugin_continentCode":"NA",
"geoplugin_latitude":"38",
"geoplugin_longitude":"-97",
"geoplugin_regionCode":"",
"geoplugin_regionName":null,
"geoplugin_currencyCode":"USD",
"geoplugin_currencySymbol":"$",
"geoplugin_currencyConverter":1
})
JSON Currency Converter
The variable “geoplugin_currencyConverter” is the conversion rate for the currency converter base currency.
Like all calls to any of geoPlugin's web services, the default base_currency is USD ($US).
Thus, if your base currency is NOT $US, then you must add the variable base_currency=XXX to the call to geoplugin.net eg
http://www.geoplugin.net/json.gp?base_currency=EUR
Now geoplugin_currencyConverter will output the exchange rate of one Euro for your visitor.
AJAX and Error: Invalid label
If you are using jQuery for example to do AJAX calls to the JSON webservice, you will probably be seeing the Javascript error Error: Invalid label
To eliminate this error, tag jsoncallback=? onto the url when making the jQuery Ajax call to any JSON webservice
eg
$.getJSON("http://www.geoplugin.net/json.gp?jsoncallback=?", function (data) { for (var i in data) { document.write('data["i"] = ' + i + '<br/>'); } );
An AJAX self-contained currency converter
Here is a working, extremely simple example of how to use the JSON service.
Here, we create a live AJAX currency converter, with little more than a few lines of HTML.
<script src="http://www.google.com/jsapi"></script> <script src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script> <script src="http://www.geoplugin.net/ajax_currency_converter.gp"></script> Convert <input type='text' id='gp_amount' size='4' /> <select id="gp_from"></select> to <select id="gp_to"></select> <p><input type='button' onClick='gp_convertIt()' value = 'Convert It' /></p> <script>gp_currencySymbols()</script> <div id="gp_converted"></div>
which will output:
See also
- In-depth User Guide
-
- JSON
-
-
