๐ฏ Inspiration
Walking through Manhattan during sunset one evening, I witnessed the famous Manhattanhenge phenomenonโthe moment when the setting sun perfectly aligns with the city's street grid, creating a stunning visual spectacle. Named by astrophysicist Neil deGrasse Tyson, this astronomical event only occurs twice a year in New York.
But then I wondered: What about other cities? Chicago has a grid layout. So does Toronto, Barcelona, and Buenos Aires. Could there be "Chicagohenge" or "Torontohenge" moments happening right now that nobody knows about?
That question sparked this project: A global Manhattanhenge finder that works for any city, anywhere in the world.
๐ What it does
Manhattanhenge is an interactive web application that calculates and visualizes when the sunset aligns with street grids in any city globally. Here's what makes it special:
- ๐ Universal Search: Type any city name (New York, Tokyo, Paris, etc.) and instantly see its street layout
- ๐ Sun Position Calculator: Uses astronomical algorithms to compute the sun's exact azimuth (compass direction) for any date and time
- ๐บ๏ธ Dynamic Street Overlay: Fetches real street data from OpenStreetMap and calculates each street's orientation
- ๐จ Visual Magic: Highlights streets that align with the sunset in vibrant orange, creating a beautiful visualization
- โฐ Time Travel: Choose any date/timeโpast, present, or futureโto see when alignments occur
- ๐ฑ Interactive UI: Draggable control panel with glassmorphism design
Use Cases:
- ๐ท Plan the perfect sunset photography session
- ๐ Educational tool for teaching astronomy and urban planning
- ๐ Discover hidden "henge" moments in your own city
- ๐๏ธ Find optimal dates for visiting cities as a tourist
๐ ๏ธ How we built it
Architecture
The project uses a Next.js full-stack architecture with TypeScript:
Frontend:
- Next.js 16 with React 19 for the UI
- Mapbox GL JS for interactive map rendering
- Tailwind CSS 4 for responsive, modern styling
- Dynamic imports to optimize bundle size
Backend:
- Next.js API Routes (serverless functions)
- SunCalc library for astronomical calculations
- OpenStreetMap Overpass API for real-time street data
The Math ๐งฎ
Sun Azimuth Calculation:
// Use SunCalc to get sun position const pos = SunCalc.getPosition(date, lat, lng); const sunAzimuth = (pos.azimuth * 180 / Math.PI + 180) % 360;- Converts sun's position to compass bearing (0ยฐ = North, 90ยฐ = East, etc.)
Street Azimuth Calculation:
// Calculate bearing between two GPS points azimuth = atan2( sin(ฮฮป) ร cos(ฯ2), cos(ฯ1) ร sin(ฯ2) - sin(ฯ1) ร cos(ฯ2) ร cos(ฮฮป) )- Fetches street geometries from OpenStreetMap
- Calculates each street segment's compass direction
- Averages azimuths for entire street
Alignment Detection:
// Compare sun and street directions const isAligned = Math.abs(streetAzimuth - sunAzimuth) <= 5ยฐ- ยฑ5ยฐ tolerance accounts for street irregularities
Data Flow
User enters city โ Mapbox Geocoding API โ Get coordinates
User selects datetime โ Frontend sends to /api/alignment
Backend calls /api/streets โ OpenStreetMap Overpass API
Calculate street azimuths โ Compare with sun azimuth
Return aligned streets โ Frontend overlays on Mapbox
๐ Challenges we ran into
OpenStreetMap Rate Limiting
- The Overpass API can be slow (10-30 seconds for dense cities)
- Solution: Added loading states and caching strategies
Coordinate System Confusion
- Mapbox uses
[lng, lat]but most APIs use[lat, lng] - Solution: Careful parameter ordering and TypeScript types
- Mapbox uses
Azimuth Calculation Accuracy
- Streets with curves have varying directions
- Solution: Calculate average azimuth across all segments
React Hot Reload Issues
- Map was re-initializing on every code change
- Solution: Added
useRefguards to prevent double initialization
Math Debugging
- Initial azimuth calculations were off by 180ยฐ
- Solution: Extensive console logging and testing with known Manhattanhenge dates
๐ Accomplishments that we're proud of
- โ Global Coverage: Works for literally any city on Earth
- โ Accurate Math: Successfully replicated real Manhattanhenge dates (May 28, July 12)
- โ Beautiful UX: Glassmorphism design with smooth animations
- โ Performance: Handles 200+ streets per city efficiently
- โ Real Data: Uses actual street geometries, not approximations
- โ Custom Domain: Deployed at manhattanhenge.tech
- โ Educational: Makes complex astronomy accessible to everyone
๐ What we learned
Technical Skills
- Astronomical Calculations: Understanding sun position algorithms
- Geospatial Math: Working with coordinates, bearings, and map projections
- API Integration: Combining multiple external APIs (Mapbox, OpenStreetMap, SunCalc)
- TypeScript Best Practices: Type-safe API contracts and data flow
- Performance Optimization: Lazy loading, debouncing, and caching strategies
Domain Knowledge
- Urban Planning: How city grids are designed (Manhattan's 29ยฐ rotation!)
- Astronomy: Solar azimuths, altitudes, and the analemma
- Cartography: Map projections and coordinate systems
Soft Skills
- Debugging Complex Systems: Tracing errors across frontend, backend, and external APIs
- Documentation: Writing clear explanations of technical concepts
- User-Centric Design: Making complex calculations feel magical
๐ What's next for Manhattanhenge
Phase 1: Community Features (Next Month)
- ๐ธ Photo Gallery: Users upload their Manhattanhenge photos
- ๐ Best Spots Database: Crowdsourced best viewing locations
- ๐๏ธ Calendar Integration: Export alignment dates to Google Calendar
Phase 2: Enhanced Visualizations (3 Months)
- ๐ 3D Sun Path: Show sun trajectory throughout the day
- ๐ฑ AR Mode: Point phone camera at street to see predicted alignment
- ๐ฅ Time-Lapse Generator: Animate sun movement across the day
Phase 3: Social & Gamification (6 Months)
- ๐ Achievement System: "Witnessed 10 Manhattanhenges"
- ๐ฅ User Profiles: Share your henge experiences
- ๐ Global Leaderboard: Most alignments discovered
Phase 4: Advanced Features (1 Year)
- ๐ค AI Predictions: Machine learning to predict best photo conditions
- ๐ค๏ธ Weather Integration: Only show alignments on clear days
- ๐ Analytics Dashboard: Heatmap of alignment frequencies globally
Long-term Vision
Transform Manhattanhenge into the Spotify of urban sunsetsโhelping millions of people discover and experience the magic of celestial alignments in their own cities.
๐ ๏ธ Built With
- Next.js 16
- React 19
- TypeScript
- Tailwind CSS 4
- Mapbox GL JS
- SunCalc
- OpenStreetMap Overpass API
- Vercel
- .tech Domain
Try it now: manhattanhenge.tech ๐
Built With
- mapbox
- nextjs
- react
- tailwind
- typescript
- vercel

Log in or sign up for Devpost to join the conversation.