The location= Parameter Is Doing More Than One Job
Most developers treat location= as a black box: pass a string in, get weather back. For straightforward cases — a major city, a clean lat/lon pair — that works fine. But the resolution path is completely different depending on what format you send, and those different paths have different accuracy characteristics, different failure modes, and different latency profiles.
A few of these will bite you in production in ways that are genuinely hard to debug if you don’t know what to look for.
Four Input Types, Four Resolution Paths
1. Lat/Lon Coordinates
This is the most direct path. Send q=51.5074,-0.1278 and the API skips any name-resolution step entirely — straight to station selection and model grid lookup against that coordinate. No geocoding roundtrip, no ambiguity about which “Springfield” you meant.
The accuracy ceiling here is determined by station density and the GRIB2 grid resolution at that location. For HRRR coverage (CONUS only, 3km grid), that’s as precise as publicly available NWP gets at this scale. Outside HRRR coverage you’re on GFS (roughly 13km) or NAM (12km for North America), so a “precise” coordinate input doesn’t buy you precision the underlying model can actually deliver.
One thing that catches people: coordinate precision beyond four decimal places is meaningless against a 3km model grid. q=51.507400,-0.127800 and q=51.5074,-0.1278 resolve to the same grid cell. Don’t bother encoding GPS-level precision unless you’re doing station-selection logic, where it does affect which METAR station wins the composite scoring.
2. City Name Strings
Send q=London and you’re invoking a geocoding step first. The name resolves to a canonical lat/lon from an internal location database, then proceeds as above. This is where ambiguity lives.
“London” is unambiguous in practice. “Birmingham” is not — Alabama or the West Midlands, depending on how resolution is weighted. We’ve had support queries where someone built against q=Paris, tested fine, deployed fine, then had a client based in Paris, Texas get confused. That’s not a bug in the usual sense; it’s what name resolution has to do when it has no additional context.
The fix is simple: be more specific. q=Paris, TX or q=Paris, France both narrow it considerably. Better still, do your own geocoding once upstream — Google Maps, Nominatim, whatever your stack already uses — cache the resulting lat/lon, and always hit the direct coordinate path. You’re never at the mercy of how the API’s internal database ranks ambiguous names.
3. US ZIP Codes
ZIP codes resolve to the centroid of that postal area’s geographic footprint. That centroid can be meaningfully far from actual population centers within the ZIP — large rural ZIPs especially, where the centroid might sit in a field rather than the town it nominally represents.
The deeper issue is that ZIP codes are postal constructs, not geographic ones. Some span terrain with real elevation variation. The centroid lands wherever it lands, and station selection plus lapse-rate correction both run from there. For most consumer use cases that’s fine. For agriculture or precision logistics covering a ZIP with 200+ square kilometers of mixed terrain, it’s not.
4. ICAO and IATA Airport Codes
Send q=EGLL (Heathrow’s ICAO code) or q=LHR (IATA) and the resolution path maps to the airport’s coordinates, then preferentially pulls the METAR observation from that airport’s own station when available. For aviation use cases that’s exactly right.
It creates a subtle problem for non-aviation queries near airports, though. Heathrow sits in the Thames Valley with its own inversion characteristics. Schiphol is essentially at sea level and surrounded by water. Neither is representative of a location 5km away on different terrain — so if you’re building a hotel booking tool and an airport code is creeping in as a fallback location string, you may be pulling conditions that belong to a genuinely different microclimate.
Use ICAO/IATA codes only when you actually want airport-specific conditions. For everything else, use coordinates.
Where Resolution Errors Actually Show Up
The place this matters most is anywhere with real topographic variation — coastal cities, mountain valleys, elevated suburbs adjacent to low-lying urban cores. Glasgow is a useful example: the city center sits at around 20m elevation, but some residential areas to the south are at 150m or more. A city-name lookup for “Glasgow” returns the city center coordinate. Someone building a hyperlocal app for Cathkin Braes gets readings that are quietly wrong by a couple of degrees in winter, with nothing in the response to signal the problem.
There’s no field in the API response that tells you “this result was computed from a geocoded city name centroid rather than your actual point of interest.” The JSON looks identical. It’s not unique to us — it’s inherent to any API that accepts name strings as location inputs. The response doesn’t distinguish between “I had a station 2km from your exact coordinate” and “I geocoded your city name to a centroid and the nearest station is 15km from there.”
The Pattern Worth Adopting
For anything beyond a quick prototype: geocode once, store coordinates, always send coordinates.
// Avoid: name resolution on every request
const url = `https://api.weatherapi.com/v1/current.json?key=${KEY}&q=Edinburgh`;
// Better: resolve name to lat/lon once, store it, reuse
const location = await resolveLocationOnce("Edinburgh"); // your own geocoder
const url = `https://api.weatherapi.com/v1/current.json?key=${KEY}&q=${location.lat},${location.lon}`;
This removes geocoding ambiguity from every subsequent request, eliminates any risk of name-resolution drift if the API’s internal database gets an update, and puts you on the highest-precision path the underlying NWP models can actually support.
If your users search by name in a UI, resolve the name in your own backend layer, present a confirmation step (“Did you mean Edinburgh, Scotland?” with a map pin), store the confirmed coordinate, and use that for all subsequent weather calls. Your app owns the geocoding; the weather API owns the weather.
One Caveat Worth Stating Plainly
None of this fixes sparse station coverage. Query a coordinate in rural Kazakhstan or the central Sahara and the nearest available station might be 80km away regardless of how precisely you’ve specified the input. The resolution path determines how well the API finds the right data for your location — it doesn’t create data that doesn’t exist.
If you’re unsure how close the backing observation actually is to your queried point, check the station object in the response. The gap between the coordinates in your request and the station coordinates in the response will tell you more about likely accuracy than anything else in the payload.
