import * as React from 'react'; import { useField } from 'payload/components/forms'; export const GeoPicker: React.FC<{ path: string }> = ({ path }) => { const { value, setValue } = useField({ path }); const [latitude, setLatitude] = React.useState(null); const [longitude, setLongitude] = React.useState(null); const handleKeyPress = async (e) => { if (e.key === 'Enter') { try { const response = await fetch( `https://nominatim.openstreetmap.org/search?format=json&q=${value}` ); const data = await response.json(); if (data && data.length > 0) { setLatitude(parseFloat(data[0].lat)); setLongitude(parseFloat(data[0].lon)); } } catch (error) { console.error('Error fetching geolocation:', error); } } }; return (
setValue(e.target.value)} onKeyDown={handleKeyPress} placeholder="Enter city to get coordinates" />
); };