Rewritten in October 2026. An earlier version presented a benchmark as measured while building MURI and showed queries MURI doesn't run. This version is a general guide, and it is explicit about what MURI actually uses.
Every location-aware backend eventually asks whether to store latitude and longitude as two numbers or adopt PostGIS. The honest answer depends on the questions you ask of the data, not on how many rows you have.
Comparing two known points: plain coordinates are fine
If the question is “is this driver within 100 metres of this stop?”, you already have both points. A geodesic or Haversine calculation in application code is exact enough and costs microseconds. On MURI, a student transport platform I worked on, that is how trip start, end and QR-pickup checks work: the stops are stored as PostGIS geography, but the distance checks compare one driver position with one known point in Python.
Searching a table by distance: this is where PostGIS earns it
“Which available drivers are within 5 km of this pickup?” is a different question: it scans many rows. With two float columns the distance expression wraps both columns in functions, so an ordinary B-tree index can't help and every candidate row is evaluated. (Note also that PostgreSQL doesn't let you filter on a SELECT alias with HAVING outside an aggregate — the filter has to repeat the expression in WHERE or use a subquery.)
-- Plain columns: correct, but every available driver is evaluated
SELECT driver_id, distance_km
FROM (
SELECT driver_id,
6371 * acos(greatest(-1.0, least(1.0,
cos(radians(:lat)) * cos(radians(lat)) * cos(radians(lng) - radians(:lng)) +
sin(radians(:lat)) * sin(radians(lat))))) AS distance_km
FROM drivers
WHERE status = 'available'
) d
WHERE distance_km < 5
ORDER BY distance_km
LIMIT 20;With PostGIS, store the location as a geography column with a GiST index and ask the index-aware question directly. Two details matter: build the search point with an explicit SRID, and query the geography column as it is — wrapping the indexed column in a cast or function can stop the planner from using the index.
-- location is geography(Point, 4326) with a GiST index
CREATE INDEX drivers_location_gix ON drivers USING gist (location);
SELECT driver_id,
ST_Distance(location, ST_SetSRID(ST_MakePoint(:lng, :lat), 4326)::geography) AS distance_m
FROM drivers
WHERE status = 'available'
AND ST_DWithin(location, ST_SetSRID(ST_MakePoint(:lng, :lat), 4326)::geography, 5000)
ORDER BY distance_m
LIMIT 20;How much faster that is depends on your data, so measure it: run both versions under EXPLAIN (ANALYZE, BUFFERS) on a realistic table and look for the index scan in the PostGIS plan.
Points in polygons
“Which service district contains this address?” is the other case where PostGIS wins outright. Implementing point-in-polygon yourself means ray casting in application code; in PostGIS it's one predicate. On geography columns, use ST_Covers; ST_Contains is a geometry function.
-- boundary is geography(Polygon, 4326)
SELECT id, name
FROM districts
WHERE ST_Covers(boundary, ST_SetSRID(ST_MakePoint(:lng, :lat), 4326)::geography);In GeoDjango, a contains lookup on a geography field can be cast internally to geometry so the operation can run. That changes the semantics from the native geography operation, and the cast can affect index use. For a point inside a surface boundary, use covers directly; use dwithin and the distance lookups for distance queries.
from django.contrib.gis.geos import Point
point = Point(lng, lat, srid=4326)
district = District.objects.filter(boundary__covers=point).first()When to skip PostGIS
- You only store a location per record and never search or filter by it.
- Every distance check compares two points you already have.
- Your managed database doesn't offer the extension.
- Approximate answers are acceptable and you can filter after fetching a small candidate set.
The verdict
Adopt PostGIS when you need to search rows by distance or relate points to areas; for checking one known point against another, plain math in your application is enough. Either way, store coordinates with an explicit SRID from day one — it's the one decision that is painful to change later.