'use client'; import React, { useState, useRef } from 'react'; import Link from 'next/link'; import { QRCodeSVG } from 'qrcode.react'; import { MapPin, Download, Check, Sparkles, Navigation, Globe } from 'lucide-react'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { cn } from '@/lib/utils'; // Brand Colors const BRAND = { paleGrey: '#ECFDF5', // Emerald-50 primary: '#10B981', // Emerald-500 primaryDark: '#047857', // Emerald-700 }; // QR Color Options const QR_COLORS = [ { name: 'Emerald', value: '#10B981' }, { name: 'Teal', value: '#0D9488' }, { name: 'Classic Black', value: '#000000' }, { name: 'Navy', value: '#1E3A8A' }, { name: 'Sky', value: '#0EA5E9' }, { name: 'Emerald', value: '#10B981' }, { name: 'Rose', value: '#F43F5E' }, ]; // Frame Options const FRAME_OPTIONS = [ { id: 'none', label: 'No Frame' }, { id: 'scanme', label: 'Scan Me' }, { id: 'location', label: 'Location' }, { id: 'map', label: 'View Map' }, ]; export default function GeolocationGenerator() { const [latitude, setLatitude] = useState(''); const [longitude, setLongitude] = useState(''); const [qrColor, setQrColor] = useState(BRAND.primary); const [frameType, setFrameType] = useState('none'); const qrRef = useRef(null); // Using Google Maps Universal Link for best compatibility const qrValue = `https://www.google.com/maps/search/?api=1&query=${latitude},${longitude}`; const handleDownload = async (format: 'png' | 'svg') => { if (!qrRef.current) return; try { if (format === 'png') { const { toPng } = await import('html-to-image'); const dataUrl = await toPng(qrRef.current, { cacheBust: true, pixelRatio: 3 }); const link = document.createElement('a'); link.download = `location-qr-code.png`; link.href = dataUrl; link.click(); } else { const svgData = qrRef.current.querySelector('svg')?.outerHTML; if (svgData) { const blob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = `location-qr-code.svg`; link.click(); } } } catch (err) { console.error('Download failed', err); } }; const getFrameLabel = () => { const frame = FRAME_OPTIONS.find(f => f.id === frameType); return frame?.id !== 'none' ? frame?.label : null; }; const getCurrentLocation = () => { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( (position) => { setLatitude(position.coords.latitude.toFixed(6)); setLongitude(position.coords.longitude.toFixed(6)); }, (error) => { console.error("Error getting location: ", error); alert("Could not access location. Please enter manually."); } ); } else { alert("Geolocation is not supported by this browser."); } }; return (
{/* Main Generator Card */}
{/* LEFT: Input Section */}
{/* Location Details */}

Coordinates

setLatitude(e.target.value)} className="h-12 text-base rounded-xl border-slate-200 focus:border-[#10B981] focus:ring-[#10B981]" />
setLongitude(e.target.value)} className="h-12 text-base rounded-xl border-slate-200 focus:border-[#10B981] focus:ring-[#10B981]" />

Tip: You can copy-paste coordinates directly from Google Maps. (Right-click a location on standard Maps, then click the coordinates to copy).

{/* Design Options */}

Design Options

{/* Color Picker */}
{QR_COLORS.map((c) => ( ))}
{/* Frame Selector */}
{FRAME_OPTIONS.map((frame) => ( ))}
{/* RIGHT: Preview Section */}
{/* QR Card with Frame */}
{/* Frame Label */} {getFrameLabel() && (
{getFrameLabel()}
)} {/* QR Code */}
{/* Info Preview */}

{latitude || 'Lat'}, {longitude || 'Long'}

Google Maps Location
{/* Download Buttons */}

Scanning opens the location directly in Google Maps.

{/* Upsell Banner */}

Need a Business Map?

Create a Dynamic QR Code for your business location. If you move, just update the location without reprinting.

); }