Geolocation Utilities

Point In Polygon

Determines if a coordinate point lies inside a polygon boundary using the ray casting algorithm. Access via MCP in Cursor or Windsurf for geofencing logic, or call GET /v1/geo/point-in-polygon directly. Pass latitude/longitude and polygon coordinates — returns true/false. The ray casting method handles complex polygons and edge cases reliably.

API Endpoint

GET /v1/geo/point-in-polygon

Code Examples

curl "https://tinyfn.io/v1/geo/point-in-polygon" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/geo/point-in-polygon', {
  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/point-in-polygon',
    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

How does the ray casting algorithm work for point-in-polygon detection?

Ray casting draws an imaginary line from the point to infinity and counts polygon edge intersections. Odd intersections mean the point is inside, even means outside.

What coordinate format does the point-in-polygon API accept?

Pass the point as latitude/longitude decimal degrees and polygon as an array of coordinate pairs in the same format.

Can I use this MCP tool for geofencing in AI agents?

Yes, AI agents in Cursor or Claude Code can check if user locations fall within delivery zones, restricted areas, or service boundaries using this tool.

Does point-in-polygon handle polygons with holes or complex shapes?

The ray casting algorithm works with any simple polygon but doesn't handle holes. For complex polygons with holes, you'll need additional logic.

What happens if the point lies exactly on a polygon edge?

Edge cases are handled consistently by the algorithm implementation, typically returning true for points on boundaries, but check your specific use case requirements.

Try Point In Polygon Now

Get your free API key and start using Point In Polygon in seconds.

Get Free API Key