Skip to main content
Glama
blake365

Macrostrat MCP Server

by blake365

lat-lng-to-tile

Convert geographic coordinates (latitude/longitude) to map tile coordinates (x, y) for specified zoom levels using web mercator projection.

Instructions

Convert latitude/longitude coordinates to map tile coordinates (x, y) for a given zoom level. Uses the same web mercator projection as MapKit.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latYesLatitude in decimal degrees (-90 to 90)
lngYesLongitude in decimal degrees (-180 to 180)
zoomYesZoom level (0-18)

Implementation Reference

  • The handler function that performs the core logic: converts latitude/longitude and zoom to tile coordinates (x, y, z) using Web Mercator projection formulas.
    async (request) => { const { lat, lng, zoom } = request; // Proper web mercator tile coordinate calculation (same as MapKit) const n = Math.pow(2, zoom); const x = Math.floor((lng + 180) / 360 * n); // Convert latitude to radians const lat_rad = lat * Math.PI / 180; // Web mercator y calculation const y = Math.floor((1 - Math.asinh(Math.tan(lat_rad)) / Math.PI) / 2 * n); const data = { x, y, z: zoom, lat, lng, zoom, note: "Use these x,y coordinates with the map-tiles tool" }; return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; }
  • Zod input schema defining parameters: lat, lng, zoom with validation and descriptions.
    { title: "Latitude/Longitude to Tile", description: "Convert latitude/longitude coordinates to map tile coordinates (x, y) for a given zoom level. Uses the same web mercator projection as MapKit.", inputSchema: { lat: z.number().min(-90).max(90).describe("Latitude in decimal degrees (-90 to 90)"), lng: z.number().min(-180).max(180).describe("Longitude in decimal degrees (-180 to 180)"), zoom: z.number().int().min(0).max(18).describe("Zoom level (0-18)"), } },
  • src/index.ts:1081-1121 (registration)
    Registration of the 'lat-lng-to-tile' tool with MCP server, including schema and handler.
    server.registerTool( "lat-lng-to-tile", { title: "Latitude/Longitude to Tile", description: "Convert latitude/longitude coordinates to map tile coordinates (x, y) for a given zoom level. Uses the same web mercator projection as MapKit.", inputSchema: { lat: z.number().min(-90).max(90).describe("Latitude in decimal degrees (-90 to 90)"), lng: z.number().min(-180).max(180).describe("Longitude in decimal degrees (-180 to 180)"), zoom: z.number().int().min(0).max(18).describe("Zoom level (0-18)"), } }, async (request) => { const { lat, lng, zoom } = request; // Proper web mercator tile coordinate calculation (same as MapKit) const n = Math.pow(2, zoom); const x = Math.floor((lng + 180) / 360 * n); // Convert latitude to radians const lat_rad = lat * Math.PI / 180; // Web mercator y calculation const y = Math.floor((1 - Math.asinh(Math.tan(lat_rad)) / Math.PI) / 2 * n); const data = { x, y, z: zoom, lat, lng, zoom, note: "Use these x,y coordinates with the map-tiles tool" }; return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/blake365/macrostrat-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server