Skip to main content
Glama
blake365

Macrostrat MCP Server

by blake365

lat-lng-to-tile

Convert latitude and longitude coordinates to map tile coordinates (x, y) for a specific zoom level using the web mercator projection, ideal for mapping and geospatial applications.

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 implements the tool logic: computes Web Mercator tile coordinates (x, y, z) from input lat, lng, and zoom, then returns formatted JSON response.
    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 schema for input validation: defines parameters lat (-90..90), lng (-180..180), zoom (int 0..18).
    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)
    Registers the "lat-lng-to-tile" tool on the MCP server with title, description, input schema, and handler function.
    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) }] }; } );

Other Tools

Related Tools

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