IP Geolocation APIs: What They Actually Tell You (and What They Do Not)
IP geolocation is great for currency defaults and fraud signals, and terrible for anything requiring precision. A developer guide to using it correctly, with request examples.
IP Geolocation APIs: What They Actually Tell You (and What They Do Not)
IP geolocation is one of the most misused APIs in web development. It is genuinely useful for a specific set of jobs and genuinely wrong for a wider set of jobs people apply it to. Knowing the difference saves you a support queue full of confused users.
What you get from an IP lookup
curl -X POST https://theglitchstore.com/api/ip-geolocation-api \
-H "x-api-key: $GLITCH_KEY" \
-H "content-type: application/json" \
-d '{"ip": "8.8.8.8"}'
Typical fields: country, region, city, approximate coordinates, timezone, and network/ASN information.
Accuracy, honestly
- Country-level: very reliable. This is the level you should build on.
- City-level: roughly right, often not. Mobile carriers route traffic through regional gateways; a user in Alexandria can resolve to Cairo. VPN users resolve wherever their exit node is.
- Coordinates: do not trust them as a location. They are frequently the centroid of a region or an ISP registration address, not the user.
- ASN/network: reliable and underused. Knowing traffic came from a datacenter ASN rather than a residential ISP is one of the strongest cheap fraud signals available.
Good uses
Currency and pricing defaults. Show EGP to Egyptian visitors, USD elsewhere — with a visible switcher. Country-level accuracy is enough.
Timezone defaults. Prefill the timezone selector. Do not lock it.
Language suggestion. Suggest Arabic to visitors from Arabic-speaking countries, never force it. Prefer the Accept-Language header when present; use IP as a fallback.
Fraud and abuse scoring. Datacenter ASN + mismatched billing country + disposable email is a much stronger signal than any of those alone.
Compliance routing. Deciding which consent banner or data-residency policy applies.
Bad uses
Store locators and delivery estimates. Ask for a postcode. IP city data will send someone to the wrong branch.
Hard geo-blocking without an appeal path. You will block legitimate travellers and VPN-using privacy-conscious users. If you must block, offer a way through.
Analytics precision claims. "Users in district X" from IP data is fiction. Country-level rollups are the honest granularity.
Anything security-critical on its own. IP location is trivially changed with a $3 VPN. It is a signal, never an authentication factor.
Implementation notes
Cache aggressively. IP-to-location mappings are stable for days. Cache per IP for at least 24 hours; you will cut your call volume by an order of magnitude on returning traffic.
Get the right IP. Behind a proxy or CDN, req.socket.remoteAddress is your load balancer. Read the forwarded header your platform actually sets, and only trust it when the request came through your own edge.
Handle IPv6. Plenty of mobile traffic is IPv6 now. If your code path assumes a dotted quad, it will silently fail for a growing share of users.
Fail open. If the lookup fails, fall back to your default currency/timezone rather than blocking the page render.
Cost shape
Geolocation is a high-volume, low-value-per-call API. That makes per-call pricing with a prepaid balance a much better fit than a subscription tier sized for a traffic level you may never hit. The IP Geolocation API draws from the same credit balance as the rest of the catalog — one key, no monthly minimum, pricing here.