How to find the distance of coordinates between two points

PHP PHP
Mainly articles about PHP

This article shows how to find the straight line distance between two points from their latitude and longitude.

What is latitude and longitude?

If you have arrived here, there is no need to explain it now, but I will explain it just in case.
Latitude and longitude are a coordinate system that expresses our position on the earth. Latitude is the angle from the equator, and longitude is the angle from the meridian line passing through the site of Greenwich Observatory in England.
Some people may find it easier to understand if they remember that longitude is in the x-direction and latitude is in the y-direction.
Using these values, we can calculate the distance between two points on the earth.

Algorithm for finding a straight line distance from latitude and longitude

Several algorithms exist to determine linear distances from latitude and longitude.
These methods can be used depending on the shape of the earth and accuracy requirements.
This article describes three typical types.

Hybeny’s Distance Formula

It is obtained from the commonly used Hybeny’s distance formula.

Haversine Formula

The GoogleMapAPI geometory.computeDistanceBetween uses this formula.
In reality, the earth is not an exact sphere but an ellipsoid, so there is an error, but the formula is simple and can be calculated quickly.

Geodesic Navigation

Finally

The above sources are available in Composer, so you can try them yourself for speed and performance.

composer require chiyoyo/distance
Bash

著者

30 years of experience as a web engineer, currently working as a freelance backend engineer.

PHP: ~30 years (Laravel 7 years / FuelPHP 5 years / CakePHP / custom frameworks)
JavaScript: ~20 years (React & Vue, 4 years each)
Cloud & Infrastructure: AWS (EC2, CloudFront, RDS, API Gateway, etc.) / GCP (BigQuery)

I have been writing PHP since version 4, back when the framework ecosystem was fragmented
and every team had their own approach. I've lived through the evolution firsthand —
from raw PHP and homegrown frameworks to the modern Laravel era —
which means I don't just know how to use a tool, but why it exists and what problem it replaced.

I work across system design, implementation, and operations, primarily on backend systems
for both product companies and contract-based projects.

On this blog, I write about the things I actually got stuck on, looked up, or figured out
in real-world projects. If something here unblocks even one person's day, that's enough for me.

千原 耕司をフォローする

役にたったと思ったら応援をお願いします m(._.)m

PHP
スポンサーリンク
シェアする
千原 耕司をフォローする
Copied title and URL