Coordinate Validation API: The Complete Guide

Need to validate geographic coordinates in your application? This guide covers everything about coordinate validation via API, including validation rules, common issues, and implementation examples in multiple languages.

Why Validate Coordinates?

Invalid coordinates can cause serious issues in your applications: mapping errors, crashed GPS systems, and incorrect geospatial calculations. Validation ensures your data is accurate before processing.

Common coordinate issues include:

  • Out-of-range values (latitude > 90 or longitude > 180)
  • Swapped latitude/longitude values
  • Invalid formats or typos
  • Coordinates in water or uninhabited areas (contextual validation)

Validation Rules

Geographic coordinates must follow these rules:

Latitude

  • Range: -90 to +90 degrees
  • -90° = South Pole
  • +90° = North Pole
  • 0° = Equator

Longitude

  • Range: -180 to +180 degrees
  • -180°/+180° = International Date Line
  • 0° = Prime Meridian (Greenwich)
Tip: A common error is swapping latitude and longitude. If a value exceeds 90 but is within 180, it's likely intended as longitude.

Using the Coordinate Validation API

TinyFn provides a comprehensive endpoint to validate coordinates:

API Request
POST https://api.tinyfn.io/v1/geo/validate
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "lat": 40.7128,
  "lng": -74.0060
}
Response
{
  "valid": true,
  "normalized": {
    "lat": 40.7128,
    "lng": -74.006
  },
  "location_type": "land",
  "warnings": []
}

Parameters

Parameter Type Description
lat number Latitude value to validate
lng number Longitude value to validate
check_swap boolean Check if lat/lng might be swapped (default: true)
check_location boolean Check if location is on land/water (default: false)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/geo/validate',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      lat: 40.7128,
      lng: -74.0060
    })
  }
);
const result = await response.json();
if (result.valid) {
  console.log('Coordinates are valid!');
} else {
  console.log('Invalid:', result.errors);
}

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/geo/validate',
    headers={'X-API-Key': 'your-api-key'},
    json={
        'lat': 40.7128,
        'lng': -74.0060
    }
)
result = response.json()
if result['valid']:
    print('Coordinates are valid!')
else:
    print('Invalid:', result['errors'])

cURL

curl -X POST "https://api.tinyfn.io/v1/geo/validate" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"lat": 40.7128, "lng": -74.0060}'

Common Use Cases

  • Form Validation: Validate user-entered coordinates before saving
  • Data Import: Clean and validate bulk coordinate imports
  • API Input Validation: Validate coordinates in your own API endpoints
  • Data Quality: Audit existing coordinate data for errors
  • ETL Pipelines: Validate coordinates during data transformation

Best Practices

  1. Validate early: Check coordinates at the point of entry
  2. Use swap detection: Catch common lat/lng swap errors
  3. Normalize precision: Round to appropriate decimal places
  4. Handle edge cases: Test with coordinates at poles and date line

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

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

See all geolocation tools available via MCP in our Geolocation MCP Tools for AI Agents guide.

Try the Coordinate Validation API

Get your free API key and start validating coordinates in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key