A developer adds a “stores near me” button and tests it on a laptop in the office, and the pin lands a few blocks off. A colleague on a phone gets the right street. Then a customer on a corporate VPN gets the wrong country entirely. All three results are normal, because geolocation is several different methods with different accuracy, and the common first assumption is that it is one dependable lookup. It is not, and most of the design decisions that follow depend on that.
Stop treating location as one lookup
The browser’s Geolocation API hands the choice to the browser, which uses the best functionality the device has, such as GPS. It works only on HTTPS pages, and it asks the user for permission when your code calls getCurrentPosition() or watchPosition() unless the choice was already made.
The alternative is to skip the device altogether and look up the visitor’s IP address, which needs no prompt at all and which is why so many sites use it for currency and language defaults, even though it is the coarsest of the methods and the easiest to fool.

Accurate on a phone, approximate everywhere else
| Method | What you get | Needs a prompt |
|---|---|---|
| Browser Geolocation API | Coordinates with an accuracy value, best on phones | Yes |
| Wi-Fi and cell tower data | Coordinates plus an accuracy radius from a service such as Google’s Geolocation API | Depends on how the app collects the signals |
| IP address lookup | Country, region or city of the network exit point | No |
Is that accurate enough? Well, it depends on whether a wrong city is a nuisance or a failure for your use case. An IP lookup tells you where the network leaves the building, which can be a different city or country from the person. VPN users and corporate networks are the usual culprits, and the annoyance is a store locator that insists on showing someone the wrong market.
Weak GPS signals indoors and out-of-date IP databases add their own errors.
One assumption does hold up. For a nearby-store search on a phone with permission granted, the browser API is good enough.
The tools split by job rather than by quality.
- Google Maps Platform covers maps, directions and distance calculations, and the Geolocation API above.
- OpenCage converts coordinates to addresses and back, drawing on several open data sources including OpenStreetMap, and its site lists a free tier of 2,500 requests a day.
- HERE sells mapping and routing, with logistics and delivery apps as a common use.
- ipstack is an IP lookup API that returns location, timezone, ISP and VPN or proxy detection across more than 100 data fields.
If the real need is a typed address, address autocomplete skips the permission prompt entirely.
Consent and privacy
People can say no, and your page must still work when they do. A denied request comes back as an error in your callback. Obviously, you want a fallback ready for those users, so write that path first.

- Ask only after a user action such as tapping the button, never on page load.
- Say what the location is used for before the prompt appears.
- Offer a typed postcode or city as the fallback.
- Store as little as possible, and a coarse area where precision is not needed.
A browser prompt is not the same thing as a legal consent record. The two laws most teams hit first treat location differently.
| Law | How location is treated |
|---|---|
| GDPR | Location data is named in the definition of personal data (Article 4) |
| CPRA (California) | Precise geolocation, meaning a location within a 1,850-foot radius, counts as sensitive personal information |
Geolocation can also feed other systems, for example geofencing with CRM systems, which makes the storage question more pressing, not less.
When not to use it
Skip geolocation when a typed postcode, a country selector or a language switch does the job. Every prompt costs some visitors, and some of them will not come back.
Do not make it a gate. A site that refuses to load without a location, or that uses an IP lookup alone to block a login, will lock out travelers and VPN users. Fraud scoring can use location as one signal among several, and a bank flagging a payment from an unusual country is a fine example of that, but the signal is not proof.
For plain “where is this server” questions, tracing a server’s location is a different tool from asking a visitor’s device.
- How to Redo in VS Code (Shortcuts and Fixes) - December 5, 2026
- Top MySQL CDC Tools for Streaming Changes to a Data Warehouse - December 4, 2026
- PyCharm Tutorial: From Install to Your First Debug Session - December 3, 2026



