Added parkLookup endpoint
This commit is contained in:
parent
dde3256c6e
commit
f714617e35
@ -6,7 +6,6 @@ import * as Location from "expo-location";
|
|||||||
import log from "@/util/log"
|
import log from "@/util/log"
|
||||||
|
|
||||||
export const API_URL = process.env.EXPO_PUBLIC_API_URL;
|
export const API_URL = process.env.EXPO_PUBLIC_API_URL;
|
||||||
|
|
||||||
const BUTTON_WIDTH = 260;
|
const BUTTON_WIDTH = 260;
|
||||||
|
|
||||||
const LocationComponent = () => {
|
const LocationComponent = () => {
|
||||||
@ -15,20 +14,34 @@ const LocationComponent = () => {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [locLoading, setLocLoading] = 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 () => {
|
const handleSubmit = async () => {
|
||||||
if (!zip) return;
|
if (!zip) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(API_URL + "/zipLookup", { zip });
|
const response = await axios.post(API_URL + "/zipLookup", { zip });
|
||||||
log.error(response.data);
|
log.error("Zip Lookup Response:", response.data);
|
||||||
const long = response.data[0];
|
const longitude = response.data[0];
|
||||||
const lat = response.data[1];
|
const latitude = response.data[1];
|
||||||
|
await fetchNearbyParks(longitude, latitude);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error(err);
|
log.error(err);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Geolocation handler
|
||||||
const handleGetLocation = async () => {
|
const handleGetLocation = async () => {
|
||||||
setLocLoading(true);
|
setLocLoading(true);
|
||||||
try {
|
try {
|
||||||
@ -41,6 +54,7 @@ const LocationComponent = () => {
|
|||||||
let location = await Location.getCurrentPositionAsync({});
|
let location = await Location.getCurrentPositionAsync({});
|
||||||
const { longitude, latitude } = location.coords;
|
const { longitude, latitude } = location.coords;
|
||||||
log.error([longitude, latitude]);
|
log.error([longitude, latitude]);
|
||||||
|
await fetchNearbyParks(longitude, latitude);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error("Location Error:", err);
|
log.error("Location Error:", err);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user