pointkit geocodes a plain address and hands back a ready-to-run ST_GeomFromText literal — correct longitude/latitude axis order, SRID 4326. Works with any PostGIS geometry or geography column.
WKT, and therefore ST_GeomFromText, expects coordinates as (longitude, latitude). Most geocoders and mapping APIs return (latitude, longitude). Swap them by mistake and Postgres accepts the geometry without complaint — the row just lands somewhere on the other side of the equator from where it should. There's no error to catch it, only a support ticket weeks later when someone notices a customer's pin is in the ocean.
pointkit geocodes the address and outputs the literal in the order Postgres expects, every time, so this class of bug never ships.
1600 Amphitheatre Parkway, Mountain View, CA is at latitude 37.4224, longitude -122.0842. PostGIS wants longitude first.
CREATE EXTENSION IF NOT EXISTS postgis; CREATE TABLE places ( id serial PRIMARY KEY, name text, geom geometry(Point, 4326) );
INSERT INTO places (name, geom)
VALUES ('Googleplex', ST_GeomFromText('POINT(-122.0842 37.4224)', 4326));
ST_X is longitude and ST_Y is latitude. If lng comes back as 37.4224, the point went in backwards.
SELECT name, ST_X(geom) AS lng, ST_Y(geom) AS lat FROM places;
A geometry column doesn't check that latitude is within ±90°, so swapped rows go in without an error. ST_FlipCoordinates swaps x and y back. This query finds every swapped row whose longitude is beyond ±90° (western North America, east Asia, Australia and New Zealand); check the rest by eye, because flipping a correct row breaks it.
UPDATE places SET geom = ST_FlipCoordinates(geom) WHERE ST_Y(geom) NOT BETWEEN -90 AND 90;
| Target | Order | Example (37.4224, -122.0842) |
|---|---|---|
| MySQL 8.0+, SRID 4326 | lat, lng | ST_GeomFromText('POINT(37.4224 -122.0842)', 4326) |
| MariaDB, MySQL 5.7 | lng, lat | ST_GeomFromText('POINT(-122.0842 37.4224)', 4326) |
| Postgres / PostGIS | lng, lat | ST_GeomFromText('POINT(-122.0842 37.4224)', 4326) |
| WKT | lng, lat | POINT(-122.0842 37.4224) |
| GeoJSON | lng, lat | {"type":"Point","coordinates":[-122.0842,37.4224]} |
| Leaflet, Google Maps | lat, lng | L.marker([37.4224, -122.0842]) |
geometry, geography and ST_GeomFromText all come from PostGIS; plain Postgres has none of them. Enable it once with CREATE EXTENSION postgis; — it’s available on Supabase, Amazon RDS, Google Cloud SQL, Azure and most other hosts.geometry or geography column — does it matter?ST_GeomFromText(...)::geography if the column is geography, or leave it as-is for a geometry column. geography is usually the better default for real-world addresses since it accounts for the Earth's curvature in distance calculations.ST_GeomFromText and WKT expect.SRID=4326;POINT(lng lat)), which a geometry or geography column accepts as a plain value, so you can load it back in with COPY or an ORM import.