Every web request carries an IP address. That IP address knows where your user is, what timezone they're in, what currency they use, and who their internet provider is. The IP Geolocation API turns that raw IP into actionable data u2014 in a single request.

This guide covers how to integrate IP geolocation into your application, what data you can extract, and common use cases that go beyond just showing a map pin.

What Is an IP Geolocation API?

An IP geolocation API takes an IP address and returns structured location data derived from network routing databases. Unlike GPS, it doesn't require any permission from the user u2014 the IP is already available on every server-side request.

A good geolocation API returns:

Making Your First Request

With the ToolCenter IP Geolocation API, you pass any IPv4 or IPv6 address and get back a structured JSON response. If you omit the IP, the API automatically geolocates the caller's IP.

cURL

curl -X GET "https://api.toolcenter.dev/v1/ip-geolocation?ip=8.8.8.8" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

{
  "ip": "8.8.8.8",
  "country": "United States",
  "country_code": "US",
  "region": "California",
  "city": "Mountain View",
  "latitude": 37.4056,
  "longitude": -122.0775,
  "timezone": "America/Los_Angeles",
  "utc_offset": "-08:00",
  "currency": "USD",
  "currency_symbol": "$",
  "isp": "Google LLC",
  "org": "Google LLC",
  "connection_type": "corporate",
  "is_proxy": false,
  "is_datacenter": true
}

Common Use Cases

1. Auto-Detect Currency and Locale

Instead of asking users to select their country during checkout, detect it automatically:

const res = await fetch('https://api.toolcenter.dev/v1/ip-geolocation', {
  headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
});
const geo = await res.json();

const locale = {
  country: geo.country_code,
  currency: geo.currency,
  timezone: geo.timezone
};

document.getElementById('country').value = locale.country;
setCurrency(locale.currency);

2. Redirect to the Right Regional Site

const geo = await getGeolocation(userIp);

const regionRoutes = {
  'US': '/en-us', 'GB': '/en-gb',
  'DE': '/de', 'FR': '/fr', 'ES': '/es',
};

const redirect = regionRoutes[geo.country_code] ?? '/en';
res.redirect(redirect);

3. Show the Correct Timezone in Dates

const geo = await getGeolocation(req.ip);

const localTime = new Intl.DateTimeFormat('en', {
  timeZone: geo.timezone,
  dateStyle: 'medium',
  timeStyle: 'short'
}).format(new Date());

console.log(`Your local time: ${localTime}`);

4. Block or Flag Datacenter IPs

const geo = await getGeolocation(req.ip);

if (geo.is_datacenter || geo.is_proxy) {
  return res.status(403).json({ error: 'Automated requests are not allowed' });
}

5. GDPR Banner for EU Users Only

import requests

def get_geo(ip, api_key):
    r = requests.get(
        "https://api.toolcenter.dev/v1/ip-geolocation",
        params={"ip": ip},
        headers={"Authorization": f"Bearer {api_key}"}
    )
    return r.json()

geo = get_geo("203.0.113.42", "YOUR_API_KEY")

EU_COUNTRIES = {"AT","BE","BG","HR","CY","CZ","DK","EE","FI","FR",
                "DE","GR","HU","IE","IT","LV","LT","LU","MT","NL",
                "PL","PT","RO","SK","SI","ES","SE"}

if geo["country_code"] in EU_COUNTRIES:
    show_gdpr_banner()

Performance Tips

Cache the Result

async function getGeolocated(ip) {
  const cacheKey = `geo:${ip}`;
  const cached = await redis.get(cacheKey);
  if (cached) return JSON.parse(cached);

  const geo = await fetchGeolocation(ip);
  await redis.setex(cacheKey, 86400, JSON.stringify(geo)); // 24h TTL
  return geo;
}

Handle Proxies in Express

app.set('trust proxy', 1);
const ip = req.ip; // real client IP behind reverse proxy
const geo = await getGeolocated(ip);

Accuracy Expectations

For locale selection, currency pre-fill, or GDPR detection u2014 country-level accuracy is all you need, and that's where geolocation excels.

Getting Started

The IP Geolocation API is included in every ToolCenter plan, including the free tier. No extra setup u2014 the same API key works for all 35+ APIs.

  1. Sign up for free and grab your API key
  2. GET /v1/ip-geolocation?ip=YOUR_IP
  3. Use country_code, timezone, and currency in your app

One key. 35+ APIs. No glue code.