This javascript API enables you to produce a more dynamic and user-friendly web browsing experience. For example, you can display a custom content depending on visitor IP location. This API returns you more than just the country, region and city name, but also the coordinate, ZIP code, time zone, ISP, domain name, IDD code, area code and weather station information. This javascript API is FREE, and you will be given 1,000 credits upon the sign up. Please note that each query will consume 1 credit. If you need more credits, you can embed the IPLocationTools Banner to replenish it.

Below is the syntax of the Javascript API.

Javascript API
<script language="javascript" src="//www.iplocationtools.com/ip-geolocation.js?key=YOUR_API_KEY"></script>

Functions Description

Function Description Sample Output
ip2location_country_flag(); Return country flag
ip2location_country_short(); Return country name (short)
ip2location_country_long(); Return country name (long)
ip2location_region(); Return region
ip2location_city(); Return city
ip2location_latitude(); Return latitude
ip2location_longitude(); Return longitude
ip2location_zip_code(); Return ZIP code
ip2location_time_zone(); Return time zone
ip2location_isp(); Return ISP
ip2location_domain(); Return domain
ip2location_net_speed(); Return net speed
ip2location_idd_code(); Return IDD code
ip2location_area_code(); Return area code
ip2location_weather_station_code(); Return weather station code
ip2location_weather_station_name(); Return weather station name
ip2location_elevation(); Return average height of city above sea level in meters (m)
ip2location_usage_type(); Return usage type classification of ISP or company

Examples

Example
<script language="JavaScript" src="//www.iplocationtools.com/ip-geolocation.js?key=YOUR_API_KEY"></script>
<script language="JavaScript">
<!--
document.write('I know you are coming from ' + ip2location_city() + ', ' + ip2location_region() + ', ' + ip2location_country_long() + '.');
//-->
</script>

Result

Example
<script language="JavaScript" src="//www.iplocationtools.com/ip-geolocation.js?key=YOUR_API_KEY"></script>
<script language="JavaScript">
<!--
var arrCurrency = new Object();
arrCurrency['US'] = 'United States dollar (USD)';
arrCurrency['GB'] = 'British Pound (GBP)';
arrCurrency['CA'] = 'Canadian dollar (CAD)';
arrCurrency['MY'] = 'Malaysian Ringgit (MYR)';
arrCurrency['JP'] = 'Japanese yen (JPY)';
arrCurrency['AU'] = 'Australian dollar (AUD)';

document.write('');
//-->
</script>

Result

Example
<script language="JavaScript" src="//www.iplocationtools.com/ip-geolocation.js?key=YOUR_API_KEY"></script>
<script language="JavaScript">
<!--
var arrCountry = new Object();
arrCountry['AF'] = 'Afghanistan';
arrCountry['AX'] = 'Åland Islands';
arrCountry['AL'] = 'Albania';
arrCountry['DZ'] = 'Algeria';
arrCountry['AS'] = 'American Samoa';
arrCountry['AD'] = 'Andorra';
arrCountry['AO'] = 'Angola';
arrCountry['AI'] = 'Anguilla';
arrCountry['AQ'] = 'Antarctica';
arrCountry['AG'] = 'Antigua and Barbuda';
arrCountry['AR'] = 'Argentina';
arrCountry['AM'] = 'Armenia';
arrCountry['AW'] = 'Aruba';
arrCountry['AU'] = 'Australia';
arrCountry['AT'] = 'Austria';
arrCountry['AZ'] = 'Azerbaijan';
arrCountry['BS'] = 'Bahamas';
arrCountry['BH'] = 'Bahrain';
arrCountry['BD'] = 'Bangladesh';
arrCountry['BB'] = 'Barbados';
arrCountry['BY'] = 'Belarus';
arrCountry['BE'] = 'Belgium';
arrCountry['BZ'] = 'Belize';
arrCountry['BJ'] = 'Benin';
arrCountry['BM'] = 'Bermuda';
arrCountry['BT'] = 'Bhutan';
arrCountry['BO'] = 'Bolivia';
arrCountry['BA'] = 'Bosnia and Herzegovina';
arrCountry['BW'] = 'Botswana';
arrCountry['BV'] = 'Bouvet Island';
arrCountry['BR'] = 'Brazil';
arrCountry['IO'] = 'British Indian Ocean Territory';
arrCountry['BN'] = 'Brunei Darussalam';
arrCountry['BG'] = 'Bulgaria';
arrCountry['BF'] = 'Burkina Faso';
arrCountry['BI'] = 'Burundi';
arrCountry['KH'] = 'Cambodia';
arrCountry['CM'] = 'Cameroon';
arrCountry['CA'] = 'Canada';
arrCountry['CV'] = 'Cape Verde';
arrCountry['KY'] = 'Cayman Islands';
arrCountry['CF'] = 'Central African Republic';
arrCountry['TD'] = 'Chad';
arrCountry['CL'] = 'Chile';
arrCountry['CN'] = 'China';
arrCountry['CX'] = 'Christmas Island';
arrCountry['CC'] = 'Cocos (Keeling) Islands';
arrCountry['CO'] = 'Colombia';
arrCountry['KM'] = 'Comoros';
arrCountry['CG'] = 'Congo';
arrCountry['CD'] = 'Congo, Democratic Republic of the';
arrCountry['CK'] = 'Cook Islands';
arrCountry['CR'] = 'Costa Rica';
arrCountry['CI'] = 'Cote D\'ivoire';
arrCountry['HR'] = 'Croatia';
arrCountry['CU'] = 'Cuba';
arrCountry['CY'] = 'Cyprus';
arrCountry['CZ'] = 'Czech Republic';
arrCountry['DK'] = 'Denmark';
arrCountry['DJ'] = 'Djibouti';
arrCountry['DM'] = 'Dominica';
arrCountry['DO'] = 'Dominican Republic';
arrCountry['EC'] = 'Ecuador';
arrCountry['EG'] = 'Egypt';
arrCountry['SV'] = 'El Salvador';
arrCountry['GQ'] = 'Equatorial Guinea';
arrCountry['ER'] = 'Eritrea';
arrCountry['EE'] = 'Estonia';
arrCountry['ET'] = 'Ethiopia';
arrCountry['FK'] = 'Falkland Islands (Malvinas)';
arrCountry['FO'] = 'Faroe Islands';
arrCountry['FJ'] = 'Fiji';
arrCountry['FI'] = 'Finland';
arrCountry['FR'] = 'France';
arrCountry['GF'] = 'French Guiana';
arrCountry['PF'] = 'French Polynesia';
arrCountry['TF'] = 'French Southern Territories';
arrCountry['GA'] = 'Gabon';
arrCountry['GM'] = 'Gambia';
arrCountry['GE'] = 'Georgia';
arrCountry['DE'] = 'Germany';
arrCountry['GH'] = 'Ghana';
arrCountry['GI'] = 'Gibraltar';
arrCountry['GR'] = 'Greece';
arrCountry['GL'] = 'Greenland';
arrCountry['GD'] = 'Grenada';
arrCountry['GP'] = 'Guadeloupe';
arrCountry['GU'] = 'Guam';
arrCountry['GT'] = 'Guatemala';
arrCountry['GN'] = 'Guinea';
arrCountry['GW'] = 'Guinea-Bissau';
arrCountry['GY'] = 'Guyana';
arrCountry['HT'] = 'Haiti';
arrCountry['HM'] = 'Heard Island and Mcdonald Islands';
arrCountry['HN'] = 'Honduras';
arrCountry['HK'] = 'Hong Kong';
arrCountry['HU'] = 'Hungary';
arrCountry['IS'] = 'Iceland';
arrCountry['IN'] = 'India';
arrCountry['ID'] = 'Indonesia';
arrCountry['IR'] = 'Iran, Islamic Republic of';
arrCountry['IQ'] = 'Iraq';
arrCountry['IE'] = 'Ireland';
arrCountry['IL'] = 'Israel';
arrCountry['IT'] = 'Italy';
arrCountry['JM'] = 'Jamaica';
arrCountry['JP'] = 'Japan';
arrCountry['JO'] = 'Jordan';
arrCountry['KZ'] = 'Kazakhstan';
arrCountry['KE'] = 'Kenya';
arrCountry['KI'] = 'Kiribati';
arrCountry['KP'] = 'Korea, Democratic People\'s Republic of';
arrCountry['KR'] = 'Korea, Republic of';
arrCountry['KW'] = 'Kuwait';
arrCountry['KG'] = 'Kyrgyzstan';
arrCountry['LA'] = 'Lao People\'s Democratic Republic';
arrCountry['LV'] = 'Latvia';
arrCountry['LB'] = 'Lebanon';
arrCountry['LS'] = 'Lesotho';
arrCountry['LR'] = 'Liberia';
arrCountry['LY'] = 'Libyan Arab Jamahiriya';
arrCountry['LI'] = 'Liechtenstein';
arrCountry['LT'] = 'Lithuania';
arrCountry['LU'] = 'Luxembourg';
arrCountry['MK'] = 'Macedonia, the Former Yugoslav Republic of';
arrCountry['MG'] = 'Madagascar';
arrCountry['MW'] = 'Malawi';
arrCountry['MY'] = 'Malaysia';
arrCountry['MV'] = 'Maldives';
arrCountry['ML'] = 'Mali';
arrCountry['MT'] = 'Malta';
arrCountry['MH'] = 'Marshall Islands';
arrCountry['MQ'] = 'Martinique';
arrCountry['MR'] = 'Mauritania';
arrCountry['MU'] = 'Mauritius';
arrCountry['YT'] = 'Mayotte';
arrCountry['MX'] = 'Mexico';
arrCountry['FM'] = 'Micronesia';
arrCountry['MD'] = 'Moldova';
arrCountry['MC'] = 'Monaco';
arrCountry['MN'] = 'Mongolia';
arrCountry['ME'] = 'Montenegro';
arrCountry['MS'] = 'Montserrat';
arrCountry['MA'] = 'Morocco';
arrCountry['MO'] = 'Mozambique';
arrCountry['MZ'] = 'Mozambique';
arrCountry['MM'] = 'Myanmar';
arrCountry['NA'] = 'Namibia';
arrCountry['NR'] = 'Nauru';
arrCountry['NP'] = 'Nepal';
arrCountry['NL'] = 'Netherlands';
arrCountry['AN'] = 'Netherlands Antilles';
arrCountry['NT'] = 'Neutral Zone';
arrCountry['NC'] = 'New Caledonia';
arrCountry['NZ'] = 'New Zealand';
arrCountry['NI'] = 'Nicaragua';
arrCountry['NE'] = 'Niger';
arrCountry['NG'] = 'Nigeria';
arrCountry['NU'] = 'Niue';
arrCountry['NF'] = 'Norfolk Island';
arrCountry['MP'] = 'Northern Mariana Islands';
arrCountry['NO'] = 'Norway';
arrCountry['OM'] = 'Oman';
arrCountry['PK'] = 'Pakistan';
arrCountry['PW'] = 'Palau';
arrCountry['PS'] = 'Palestinian Territory, Occupied';
arrCountry['PA'] = 'Panama';
arrCountry['PG'] = 'Papua New Guinea';
arrCountry['PY'] = 'Paraguay';
arrCountry['PE'] = 'Peru';
arrCountry['PH'] = 'Philippines';
arrCountry['PN'] = 'Pitcairn';
arrCountry['PL'] = 'Poland';
arrCountry['PT'] = 'Portugal';
arrCountry['PR'] = 'Puerto Rico';
arrCountry['QA'] = 'Qatar';
arrCountry['RE'] = 'Reunion';
arrCountry['RO'] = 'Romania';
arrCountry['RU'] = 'Russian Federation';
arrCountry['RW'] = 'Rwanda';
arrCountry['SH'] = 'Saint Helena';
arrCountry['KN'] = 'Saint Kitts and Nevis';
arrCountry['LC'] = 'Saint Lucia';
arrCountry['PM'] = 'Saint Pierre and Miquelon';
arrCountry['VC'] = 'Saint Vincent and the Grenadines';
arrCountry['WS'] = 'Samoa';
arrCountry['SM'] = 'San Marino';
arrCountry['ST'] = 'Sao Tome and Principe';
arrCountry['SA'] = 'Saudi Arabia';
arrCountry['SN'] = 'Senegal';
arrCountry['RS'] = 'Serbia';
arrCountry['CS'] = 'Serbia and Montenegro';
arrCountry['SY'] = 'Seychelles';
arrCountry['SC'] = 'Seychelles';
arrCountry['SL'] = 'Sierra Leone';
arrCountry['SG'] = 'Singapore';
arrCountry['SK'] = 'Slovakia';
arrCountry['SI'] = 'Slovenia';
arrCountry['SB'] = 'Solomon Islands';
arrCountry['SO'] = 'Somalia';
arrCountry['ZA'] = 'South Africa';
arrCountry['GS'] = 'South Georgia and the South Sandwich Islands';
arrCountry['ES'] = 'Spain';
arrCountry['LK'] = 'Sri Lanka';
arrCountry['SD'] = 'Sudan';
arrCountry['SR'] = 'Suriname';
arrCountry['SJ'] = 'Svalbard and Jan Mayen Islands';
arrCountry['SZ'] = 'Swaziland';
arrCountry['SE'] = 'Sweden';
arrCountry['CH'] = 'Switzerland';
arrCountry['TW'] = 'Taiwan';
arrCountry['TJ'] = 'Tajikistan';
arrCountry['TZ'] = 'Tanzania, United Republic of';
arrCountry['TH'] = 'Thailand';
arrCountry['TL'] = 'Timor-Leste';
arrCountry['TG'] = 'Togo';
arrCountry['TK'] = 'Tokelau';
arrCountry['TO'] = 'Tonga';
arrCountry['TT'] = 'Trinidad and Tobago';
arrCountry['TN'] = 'Tunisia';
arrCountry['TR'] = 'Turkey';
arrCountry['TM'] = 'Turkmenistan';
arrCountry['TC'] = 'Turks and Caicos Islands';
arrCountry['TV'] = 'Tuvalu';
arrCountry['UG'] = 'Uganda';
arrCountry['UA'] = 'Ukraine';
arrCountry['AE'] = 'United Arab Emirates';
arrCountry['GB'] = 'United Kingdom';
arrCountry['UK'] = 'United Kingdom';
arrCountry['US'] = 'United States';
arrCountry['UY'] = 'Uruguay';
arrCountry['UZ'] = 'Uzbekistan';
arrCountry['VU'] = 'Vanuatu';
arrCountry['VA'] = 'Vatican City State';
arrCountry['VE'] = 'Venezuela';
arrCountry['VN'] = 'Viet Nam';
arrCountry['VG'] = 'Virgin Islands, British';
arrCountry['VI'] = 'Virgin Islands, U.S.';
arrCountry['WF'] = 'Wallis and Futuna Islands';
arrCountry['EH'] = 'Western Sahara';
arrCountry['YE'] = 'Yemen';
arrCountry['YU'] = 'Yugoslavia';
arrCountry['ZM'] = 'Zambia';
arrCountry['ZW'] = 'Zimbabwe';

document.write('');
//-->
</script>

Result

Example
<script language="JavaScript" src="//www.iplocationtools.com/ip-geolocation.js?key=YOUR_API_KEY"></script>
<script language="JavaScript">
<!--
document.write('Click here to show ' + ip2location_city() + ' in Google map.');
//-->
</script>

Result

IP2Location IP Geolocation

IP2Location Free Widget

IP2Location Firefox Add-on

IP Address Map