BlogAPI design

Name the coordinates before the request

GeoJSON positions put longitude first. Convert that ordered pair into named latitude and longitude fields before making a Point request.

A map hands your application two numbers. Before passing them to another service, check what each position means. An array doesn't tell you whether its first number is latitude or longitude.

GeoJSON does define that order. Its positions use longitude first, then latitude, as described in RFC 7946. This example represents the Denver coordinates used in the Point API examples:

{
  "type": "Point",
  "coordinates": [-104.9, 39.77]
}

Point accepts named query parameters, so turn the ordered pair into names at the boundary:

const [longitude, latitude] = feature.geometry.coordinates;
const query = new URLSearchParams({
  lat: String(latitude),
  lon: String(longitude)
});
const path = `/point?${query}`;

For that example, the path is /point?lat=39.77&lon=-104.9. The snippet assumes a GeoJSON feature whose geometry is a Point. Check the geometry type before using it, because a line or polygon has a different array structure. An optional third coordinate is altitude in GeoJSON. It is not another value to put in the longitude field, and Point does not accept it as an elevation override.

The names make the request easier to inspect and keep the array convention from spreading into the rest of the application. If a different map library returns latitude first, give that boundary its own adapter based on the library's documented order. Reusing a generic "first, second" pair would hide the difference again.

Point checks latitude from -90 to 90 and longitude from -180 to 180. Swapping this Denver pair produces a latitude of -104.9, so the request rejects it. That is a useful catch, but it doesn't catch every swap. With a pair such as [-0.1, 51.5], both orders fit the allowed ranges. The other order simply describes a different point.

Once your adapter assigns the correct names, keep those names through storage and request construction. The response also includes latitude and longitude, which you can compare with the values you intended to submit. A successful lookup tells you about the submitted point. The adapter is what connects it to the point the person selected on the map.

The Point reference describes the place and timezone fields returned for those coordinates.