Search⌘ K

Finding the Nearest Pub

Explore how to use PostgreSQL’s earthdistance extension to compute accurate distances between longitude and latitude points on Earth. Learn to query and analyze pub location data to find the nearest pubs based on geographic proximity with efficient SQL techniques.

How far is the nearest pub?

Computing the distance between two given positions on the Earth, expressed as longitude and latitude, is not that easy. It involves knowing how to process the Earth as a sphere and some knowledge of the projection system in which the coordinates are valid. PostgreSQL makes it easy to solve, though, thanks to the earthdistance extension included in contribs.

The earthdistance PostgreSQL contrib

As mathematical operations are complex enough to easily make mistakes when implementing them again, ...