Set lon/lat on data fetch
continuous-integration/drone/push Build is passing Details

This commit is contained in:
toqvist 2024-02-21 16:36:39 +01:00
parent 26eb75646b
commit f152476d8f
1 changed files with 3 additions and 6 deletions

View File

@ -1,15 +1,13 @@
import * as React from 'react';
import { useField, Label, TextInput } from 'payload/components/forms';
import { useField } from 'payload/components/forms';
export const GeoPicker: React.FC<{ path: string }> = ({ path }) => {
const { value, setValue } = useField<string>({ path });
const [latitude, setLatitude] = React.useState("");
const [longitude, setLongitude] = React.useState("");
const [longitude, setLongitude] = React.useState(value[0]);
const [latitude, setLatitude] = React.useState(value[1]);
const handleCityEnter = async (e) => {
console.log("Handle key")
if (e.key === 'Enter') {
console.log("Enter: " + e.target.value)
try {
const response = await fetch(
`https://nominatim.openstreetmap.org/search?format=json&q=${e.target.value}`
@ -20,7 +18,6 @@ export const GeoPicker: React.FC<{ path: string }> = ({ path }) => {
setLatitude(lat);
setLongitude(lon);
setValue([lon, lat]);
console.log(data)
}
} catch (error) {
console.error('Error fetching geolocation:', error);