Developers
Validate Coordinates Before API Calls
Check latitude and longitude ranges, types and placeholder values before calling UPCS, to avoid 422 errors and wasted hourly requests.
Updated 14 October 2026 · 2 min read
Sending bad coordinates costs a request against your hourly limit and returns a 422. A few cheap checks in your own code avoid that and give users faster, clearer messages.
The checks
- Present and numeric. Reject null, empty strings and non-numbers.
- In range. Latitude between -90 and 90; longitude between -180 and 180.
- Not a placeholder.
0, 0is often a default for "unknown". Treat it as missing unless you are sure. - Order. Swapped values are common. A latitude above 90 in magnitude is a giveaway that the pair is reversed.
- Precision. Round to six decimals for storage and cache keys; see storing coordinates in a database.
A helper
function parseCoordinates(latInput, lngInput) {
const lat = Number(latInput);
const lng = Number(lngInput);
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return null;
if (lat < -90 || lat > 90) return null;
if (lng < -180 || lng > 180) return null;
if (lat === 0 && lng === 0) return null;
return {
lat: Math.round(lat * 1e6) / 1e6,
lng: Math.round(lng * 1e6) / 1e6
};
}
Remember the field names
Resolve expects lat and lng; generate expects latitude and longitude. A helper that returns neutral names and maps them per call avoids silly mistakes.
$payload = ['latitude' => $coords['lat'], 'longitude' => $coords['lng']];
What validation cannot tell you
A coordinate can be perfectly valid and still sit in the ocean or in a country UPCS does not cover. The API answers with 422 unsupported_location for points outside the 25 supported countries; see handling the unsupported_location error.
Return friendly messages
Map each failure to something a visitor understands: "That location is not valid. Please choose a point on the map." Log the technical detail separately. The full list of responses is in the error codes reference.
Frequently asked questions
What range is valid?
Latitude from -90 to 90 and longitude from -180 to 180. Values outside these ranges are invalid.
Does passing validation guarantee a code?
No. A valid coordinate can still fall outside the supported countries, which returns the unsupported_location error.
