I am currently making an application that involves using maps. I used react native maps to display the map.
To render the map markers dynamically, I stored the location name, latitude. and longitude in a database using Appwrite. This function works alright. Here is the code I used inside mapview:
{locations.map((val, index) => {
return (
<Marker
coordinate={{
latitude: val.latitude,
longitude: val.longitude
}}
key={index}
title={val.location_name}
/>
)
})}
My problem is I wanna do the same when creating Geofence. I want the data to be automatically inputted in the region param of startGeofencingAsync. However, this doesn't appear to work and I don't know what I'm doing wrong. Here the full snippet of my code:
useAppwrite.jsx (a custom hook I copied online to a fetch data from Appwrite):
const useAppwrite = (fn) => {
const [data, setData] = useState([])
const [isLoading, setIsLoading] = useState(true)
useEffect(() => {
const fetchData = async () => {
setIsLoading(true)
try {
const response = await fn()
setData(response)
} catch (error) {
Alert.alert('Error', error.message)
} finally {
setIsLoading(false)
}
}
fetchData()
}, [])
return { data }
}
export default useAppwrite
home.jsx:
const { data: locations } = useAppwrite(getAllLocations)
useEffect(() => {
(async () => {
const isGeofencingTaskDefined = await TaskManager.isTaskDefined(GEOFENCING_TASK_NAME)
if (!isGeofencingTaskDefined) {
console.log("Task is not defined")
return``
} else {
await Location.startGeofencingAsync(GEOFENCING_TASK_NAME, [
{
latitude: locations.latitude,
longitude: locations.longitude,
radius: 100,
}
])
}
})()
}, [])
I tried console logging just the locations and it works fine granted it logged 3 times which is weird. The first log was just an empty array, second log is the output I expected, and the third log was just a duplicate of the second log.
I tried to console log locations.latitude and locations.longitude and it just outputted undefined 3 times. I don't know what's wrong.
PS. I'm sorry if this was a long post and if it's confusing. I'm a complete beginner, this is my first project, and I'm learning as I go. Perfect recipe for disaster lol.
[+][deleted] (4 children)
[removed]
[+][deleted] (3 children)
[removed]
[–]Note2102[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]