A geographic point needs an explicit coordinate order and reference system. Latitude is bounded by the poles; longitude wraps around the globe. A screen map applies a projection, so equal pixel gaps are not equal ground distances everywhere. Coordinates in degrees must not be passed to a distance function that expects meters without a defined conversion or geographic type. A rectangular viewport crossing the antimeridian is two longitude intervals rather than one ordinary increasing interval. Server and browser must agree about these representations before filtering records or placing markers.
Coordinate Validation, Projection, and the Antimeridian
Working case
A facilities team stores a pump inspection at latitude 13.036 and longitude 77.610. A client sends [longitude, latitude], but an API decoder reads [latitude, longitude]; the point appears thousands of kilometers away while both numbers still fit plausible numeric ranges. Another facility near longitude 179.7 appears to vanish when the map pans across the antimeridian because the query assumes west is always less than east. The revised contract uses named latitude and longitude fields, validates ranges, records the coordinate reference system, and splits a crossing viewport into two longitude predicates. The map label reports approximate distance rather than pretending a projected pixel measurement is a survey result.
Implementation boundary
function validFacilityPoint(point) {
return Number.isFinite(point.latitude) && Number.isFinite(point.longitude) &&
point.latitude >= -90 && point.latitude <= 90 &&
point.longitude >= -180 && point.longitude <= 180;
}
console.log(validFacilityPoint({ latitude: 96, longitude: 77.610 }));
// Output: falseUse named fields at application boundaries and one documented point order inside geometry libraries. Reject nonfinite values, latitudes outside -90 through 90, and longitudes outside -180 through 180. Decide whether longitude 180 and -180 are normalized to one identity before deduplicating. Carry the geometry reference system with stored values and transform explicitly for rendering. When filtering a viewport, split an antimeridian crossing into west-to-180 and -180-to-east; do not swap endpoints to make the numbers increasing. Use geodesic or geography-aware distance for meter-based nearby results and state the measurement approximation. Check that a point is authorized before returning it, since a valid coordinate is still private case data. Avoid printing exact coordinates in public error messages.
Cost and boundaries
Validation is O(1) per point and O(N) for N imported points. A coordinate transform is O(N) before indexing, so precompute or index the stored form used by common queries where appropriate. A naive scan of all facilities for each viewport is O(N) per pan and becomes expensive as the catalog grows. Indexed bounding filters reduce candidates but may need exact post-filtering, especially near a seam or projection edge. Precision increases storage and privacy exposure without always improving the task. Measure rejected coordinates, transformed records, query candidates, out-of-viewport markers, and distance disagreement in representative regions.
Failure trace
Swap latitude and longitude for a point where both values fit legal ranges and verify a contract test catches the order mismatch. Send NaN, infinity, and a latitude of 96; reject before storage. Query a viewport from longitude 178 to -177 and confirm facilities on both sides of the seam appear. Compare a distance label at two latitudes for the same projected pixel gap and avoid using pixels as meters. Import a geometry with an unexpected reference system and require explicit transformation. Ask for a private facility point as another tenant and deny it even though its coordinates are otherwise valid.
Verification
- Coordinate order is named and contract-tested.
- A crossing viewport includes both sides of the seam.
- Distance units are explicit and not inferred from pixels.
Practice drill
Define a point payload for pump 47 with latitude 13.036, longitude 77.610, and a declared geographic reference system. Import 63 valid and 7 malformed records. Query a viewport that crosses the antimeridian and count records on each side. Compute a nearby label through a meter-aware service rather than screen pixels. Pan the map while a stale viewport request remains in flight; discard its markers after the new viewport identity wins.
Decision note
Coordinates are data with units and order; a map projection is only one display of that data.
Common Mistakes
- Treating longitude and latitude as interchangeable tuple positions.
- Using degree differences as meters.
- Sorting antimeridian bounds into one ordinary interval.
Related lessons
Geospatial Web Interfaces and Spatial Queries; Map Viewport Tiles and Request Lifecycle; Nearby Spatial Search and Tenant Filter; Location Consent, Precision, and Map Alternatives; Geolocation Accuracy, Cancellation, and Retention; Typed Frontend and Component Platform.
Connected practice
Build Project: authorized facility map and nearby search and review Web Development: geospatial decisions quiz.
