import React, { useState } from "react"; import { Dialog, TextInput, useTheme, Button, Text } from "react-native-paper"; import { View } from "react-native"; import axios from "axios"; import * as Location from "expo-location"; import log from "@/util/log" export const API_URL = process.env.EXPO_PUBLIC_API_URL; const BUTTON_WIDTH = 260; const LocationComponent = () => { const theme = useTheme(); const [zip, setZip] = useState(""); const [loading, setLoading] = useState(false); const [locLoading, setLocLoading] = useState(false); // Call the parks endpoint with coordinates const fetchNearbyParks = async (longitude: number, latitude: number) => { try { const range = 25; const response = await axios.post(API_URL + "/parkLookup", { "Lon": longitude, "Lat": latitude, "Dist": range }); log.error("Nearby Parks:", response.data); // handle parks as you need } catch (err) { log.error("Nearby Parks Error:", err); } }; // Zip code handler const handleSubmit = async () => { if (!zip) return; setLoading(true); try { const response = await axios.post(API_URL + "/zipLookup", { zip }); log.error("Zip Lookup Response:", response.data); const longitude = response.data[0]; const latitude = response.data[1]; await fetchNearbyParks(longitude, latitude); } catch (err) { log.error(err); } setLoading(false); }; // Geolocation handler const handleGetLocation = async () => { setLocLoading(true); try { let { status } = await Location.requestForegroundPermissionsAsync(); if (status !== 'granted') { log.error("Permission to access location was denied"); setLocLoading(false); return; } let location = await Location.getCurrentPositionAsync({}); const { longitude, latitude } = location.coords; log.error([longitude, latitude]); await fetchNearbyParks(longitude, latitude); } catch (err) { log.error("Location Error:", err); } setLocLoading(false); }; return ( OR ); }; export default LocationComponent;