geoPlugin Home

JSON Geolocation Web Service

The JSON Geolocation web service API 1) 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. If you are calling the JSON service via jQuery, you don't need to include the IP since the IP will be automatically resolved to your visitor.

Example output of a JSON query for your IP address (44.206.248.122) is:

{
	
  "geoplugin_request":"44.206.248.122",
	
  "geoplugin_status":200,
  "geoplugin_delay":"1ms",
	
  "geoplugin_credit":"Some of the returned data includes GeoLite2 data created by MaxMind, available from https:\/\/www.maxmind.com<\/a>.",
	
  "geoplugin_city":"Ashburn",
	
  "geoplugin_region":"Virginia",
	
  "geoplugin_regionCode":"VA",
	
  "geoplugin_regionName":"Virginia",
	
  "geoplugin_areaCode":"",
	
  "geoplugin_dmaCode":"511",
	
  "geoplugin_countryCode":"US",
	
  "geoplugin_countryName":"United States",
	
  "geoplugin_inEU":0,
  "geoplugin_euVATrate":false,
  "geoplugin_continentCode":"NA",
	
  "geoplugin_continentName":"North America",
	
  "geoplugin_latitude":"39.0469",
	
  "geoplugin_longitude":"-77.4903",
	
  "geoplugin_locationAccuracyRadius":"1000",
	
  "geoplugin_timezone":"America\/New_York",
	
  "geoplugin_currencyCode":"USD",
	
  "geoplugin_currencySymbol":"$",
	
  "geoplugin_currencySymbol_UTF8":"$",
	
  "geoplugin_currencyConverter":0

}




JSON Geolocation 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.

The base_currency value must be a valid ISO 4217 3-letter code.


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


This is due to data requests from a server (geoPlugin) in a different domain (your web server). To eliminate this problem, JSONP or “JSON with padding” is required.
To return the JSON results as JSONP, 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:

Convert to




See also

1) This product includes GeoLite data created by MaxMind, available from http://maxmind.com/
 
 


Acceptable Use Policy    Privacy Policy and User Agreement    Contact geoPlugin


©2006 - 2024 geoPlugin® is a registered trademark of GEOPLUGIN, SAS