I am trying to get location from all documents of my collection, but in this way I am getting just one document lat and long.
I need to get all lat and long data from all documents and show it in my map
what I am doing wrong??
can anyone help me with it??
POINTS STATE:
const [points, setPoints] = useState([]);
useEffect(() => {
async function getProviderLocation() {
try {
const db = firestore();
await db
.collection('Providers')
.get()
.then(snapshot => {
if (snapshot.empty) {
console.log('nao tem');
return;
}
console.log('docss', snapshot.docs);
snapshot.forEach(async doc => {
// console.log('ID', doc.id);
setPoints([
...points,
{
id: doc.id,
latitude: doc.data().address.latitude,
longitude: doc.data().address.longitude,
},
]);
console.log('points', points);
});
})
.catch(err => {
console.log('Error getting documents', err);
});
} catch (error) {
console.log(error);
}
}
if (coordinates) getProviderLocation();
}, []);
RENDERING:
{points.map(point => (
<Marker
onPress={() => navigateToCreateAppointment(point.id)}
style={styles.mapMarkerImage}
key={point.id}
coordinate={{
latitude: parseFloat(point.latitude),
longitude: parseFloat(point.longitude),
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
}}
>
<Image source={wingImg} />
</Marker>
))}