Skip to content

Geo

The /geo endpoint calculates the distance and bearing between two GPS coordinates using the Haversine formula.

How it works?

The Haversine formula computes the great-circle distance between two points on a sphere — the shortest path over the Earth's surface, ignoring elevation. Bearing is the initial compass heading from point A to point B, expressed in degrees (0° = North) and as a cardinal direction.

Parameters

ParameterRequiredDescription
lat1YesLatitude of point A (-90/+90)
lon1YesLongitude of point A (-180/+180)
lat2YesLatitude of point B (-90/+90)
lon2YesLongitude of point B (-180/+180)

Response Fields

FieldTypeDescription
distance.kmnumberDistance in kilometers
distance.milesnumberDistance in miles
distance.nauticalMilesnumberDistance in nautical miles
bearing.degreesnumberBearing in degrees (0–360)
bearing.cardinalstringCardinal direction (N, NNE, NE, ENE, E, etc.)
from.latnumberParsed latitude of point A
from.lonnumberParsed longitude of point A
to.latnumberParsed latitude of point B
to.lonnumberParsed longitude of point B

Code Examples

curl -X GET \
  "https://api.sylvain.sh/v5/geo?lat1=48.8566&lon1=2.3522&lat2=43.2965&lon2=5.3698"

Try It

Error Handling

If parameters are missing or invalid, the API will return an error:

Error MessageDescription
lat1 must be a numberA coordinate is not a valid number
lat1 must be between -90 and 90Latitude is out of range
lon1 must be between -180 and 180Longitude is out of range