UNPKG

ttbkk-mcp-server

Version:

MCP server providing access to Korean tteokbokki restaurant database with search, location-based queries, and brand information

74 lines 2.77 kB
import { supabase } from '../lib/supabase.js'; /** * Calculate distance between two coordinates using Haversine formula * @param lat1 - Latitude of first point * @param lon1 - Longitude of first point * @param lat2 - Latitude of second point * @param lon2 - Longitude of second point * @returns Distance in kilometers */ function calculateDistance(lat1, lon1, lat2, lon2) { const R = 6371; // Earth's radius in kilometers const dLat = (lat2 - lat1) * (Math.PI / 180); const dLon = (lon2 - lon1) * (Math.PI / 180); const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1 * (Math.PI / 180)) * Math.cos(lat2 * (Math.PI / 180)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return R * c; } /** * Get nearby tteokbokki restaurants within specified radius * @param latitude - Center point latitude * @param longitude - Center point longitude * @param radius - Search radius in kilometers * @param limit - Maximum number of results to return * @returns Array of nearby restaurants with distance */ export async function getNearbyRestaurants(latitude, longitude, radius = 1, limit = 10) { try { // 반경 내 대략적인 bounding box 계산 (1도 ≈ 111km) const latDelta = radius / 111; const lonDelta = radius / (111 * Math.cos(latitude * (Math.PI / 180))); const { data, error } = await supabase .from('place') .select(` *, brand ( *, hashtags:brand_hashtags!brand_id ( hashtag_id ) ), hashtags:place_hashtags!place_id ( hashtag_id ) `) .eq('is_deleted', false) .gte('latitude', latitude - latDelta) .lte('latitude', latitude + latDelta) .gte('longitude', longitude - lonDelta) .lte('longitude', longitude + lonDelta); if (error) { console.error('Supabase error:', error); throw new Error(`Failed to find nearby restaurants: ${error.message}`); } // 정확한 거리 계산 및 필터링 const nearbyRestaurants = (data || []) .map((restaurant) => ({ ...restaurant, distance: calculateDistance(latitude, longitude, restaurant.latitude, restaurant.longitude), })) .filter((restaurant) => restaurant.distance <= radius) .sort((a, b) => a.distance - b.distance) .slice(0, limit); return nearbyRestaurants; } catch (error) { console.error('Error finding nearby restaurants:', error); throw error; } } //# sourceMappingURL=nearby-search.js.map