Geolocation Utilities

Haversine Distance

Calculates great-circle distance between two GPS coordinates using the Haversine formula. Access via GET /v1/geo/haversine with lat/lng pairs, returns precise distances in kilometers or miles. Essential for location-based apps, delivery routing, and proximity searches. MCP integration lets Cursor and other AI tools perform accurate geographic calculations without approximation errors.

API Endpoint

GET /v1/geo/haversine

Code Examples

curl "https://tinyfn.io/v1/geo/haversine" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/geo/haversine', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/geo/haversine',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's geolocation tools:

{
  "mcpServers": {
    "tinyfn-geo": {
      "url": "https://tinyfn.io/mcp/geo",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

What's the difference between Haversine and straight-line distance?

Haversine calculates distance along Earth's curved surface (great-circle), while straight-line goes through the planet. For GPS coordinates, Haversine gives real-world travel distance.

How do I calculate distance between New York and London using the API?

GET /v1/geo/haversine?lat1=40.7128&lng1=-74.0060&lat2=51.5074&lng2=-0.1278 returns approximately 5585 kilometers between the coordinates.

Can MCP tools use Haversine for location-based features in code?

Yes, AI agents in Cursor or Windsurf can call this tool to build proximity searches, delivery radius calculations, or geographic filters with precise distance measurements.

What's the accuracy limit of Haversine formula?

Haversine assumes perfect sphere, with ~0.5% error on Earth. For most applications under 1000km, it's sufficiently accurate for GPS-based calculations.

Does the API return results in miles or kilometers?

Default output is kilometers. Most implementations allow unit parameter (km/miles) - check the specific endpoint documentation for unit conversion options.

Try Haversine Distance Now

Get your free API key and start using Haversine Distance in seconds.

Get Free API Key