IP Geolocation API JQuery SDK
Introduction
IPGeolocation API is the solution to identify country code (ISO2 and ISO3 standard), country name, continent code, continent name, country capital, state/province, district, city, zip code, latitude and longitude of city, is country belongs to Europian Union, calling code, top level domain (TLD), languages, country flag, internet service provider (ISP), connection type, organization, geoname ID, currency code, currency name, time zone ID, time zone offset, current time in the time zone, is time zone in daylight saving time, and total daylight savings. This document provides important information to help you get up to speed with IPGeolocation API using IP Geolocation API JQuery SDK.
Developers can use this JQuery SDK for software and web projects related to, but not limited to:
- Display native language and currency
- Redirect based on the country
- Digital rights management
- Web log stats and analysis
- Auto-selection of country, state/province and city on forms
- Filter access from countries you do not do business with
- Geo-targeting for increased sales and click-through
Quick Start Guide
You need a valid 'IPGeolocation API key' to use this SDK. Sign up here and get your free API key if you don't have one.
Note: Complete documentation to use this SDK is also available at IP Geolocation API JQuery SDK Documentation.
System Requirements
Internet connection is required to run this component.
Installation
CDN Link
Add the following script in your HTML page:
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.9/ipgeolocation.min.js"></script>
Geolocation Lookup
You can use this SDK without an API key if you're using the Request Origin feaure on IP Geolocation API.
Here are a few different ways of querying Geolocation for an IP address from IP Geolocation API.
function handleResponse(response) {
console.log(response);
}
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
_ipgeolocation.getGeolocation(handleResponse);
_ipgeolocation.enableSessionStorage(true);
_ipgeolocation.makeAsyncCallsToAPI(false);
_ipgeolocation.setIPAddress("1.1.1.1");
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
_ipgeolocation.setLanguage("ru");
_ipgeolocation.setIPAddress("1.1.1.1");
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
_ipgeolocation.setFields("geo,time_zone,currency");
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
_ipgeolocation.setFields("geo,time_zone,currency");
_ipgeolocation.setIPAddress("1.1.1.1");
_ipgeolocation.setExcludes("ip");
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
Time Zone API
Here are a few examples to query Time Zone information from Timezone API.
function handleResponse(response) {
console.log(response);
}
_ipgeolocation.getTimezone(handleResponse, "YOUR_API_KEY");
_ipgeolocation.getTimezone(handleResponse);
_ipgeolocation.enableSessionStorage(true);
_ipgeolocation.makeAsyncCallsToAPI(false);
_ipgeolocation.setIPAddress("1.1.1.1");
_ipgeolocation.setLanguage("it");
_ipgeolocation.getTimezone(handleResponse, "YOUR_API_KEY");
_ipgeolocation.setTimeZone("America/Los_Angeles");
_ipgeolocation.getTimezone(handleResponse, "YOUR_API_KEY");
_ipgeolocation.setCoordinates("31.4816", "74.3551");
_ipgeolocation.getTimezone(handleResponse, "YOUR_API_KEY");
Example
Here is a sample code to use IP Geolocation API using JQuery SDK:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ip-geolocation-api-jquery-sdk@1.0.9/ipgeolocation.min.js"></script>
<script>
_ipgeolocation.enableSessionStorage(true);
var ip = sessionStorage.getItem("ip");
var country_name = sessionStorage.getItem("country_name");
var country_code2 = sessionStorage.getItem("country_code2");
if (!ip || !country_name || !country_code2) {
_ipgeolocation.makeAsyncCallsToAPI(false);
_ipgeolocation.setFields("country_name,country_code2");
_ipgeolocation.getGeolocation(handleResponse, "YOUR_API_KEY");
}
function handleResponse(json) {
ip = json.ip;
country_name = json.country_name;
country_code2 = json.country_code2;
}
$(document).ready(function() {
alert("Hello " + country_name + "!");
});
</script>
** IPGeolocation provides geolocation information in the following languages:
- English (en)
- German (de)
- Russian (ru)
- Japanese (ja)
- French (fr)
- Chinese Simplified (cn)
- Spanish (es)
- Czech (cs)
- Italian (it)
By default, geolocation information is returned in English. Response in a language other than English is available to paid users only.