I'm coding using react + firestore 9 on an application that has to render a google map and then depending on the query it shows some markers.
I've been trying to get the aplication to draw some basic markers with some data I'm fetching from the database, the query is executed as quickly as it can, I've tried a lot of solutions but the map is not rendering the markers for me. The following is the code I'm using in the component:
function fetchMarkers(){
var markerData = [];
getDocs(query(collection(db, "places")))
.then((foo) => {
foo.forEach((doc) => {
markerData.push(doc.data())
})
})
return markerData;
}
var arrayData = [];
export default function Map() {
fetchMarkers().then((value) => {
arrayData = value;
console.log(arrayData)
})
return (
<div id="map">
<LoadScript
googleMapsApiKey={apiKey}>
<GoogleMap
mapContainerStyle={containerStyle}
center={center}
zoom={13}
options={{ fullscreenControl: false, mapTypeControl: false, streetViewControl: false, styles: [{ elementType: "labels", featureType: "poi", stylers: [{ visibility: "off", }], }], }}>
{arrayData.map((marker) =>
<Marker
key={marker.id}
position={{
lat: marker.latitud,
lng: marker.longitud
}}
/>)
}
</GoogleMap>
</LoadScript>
</div>
)
What is happening here is that the page is loading before the arrayData fills with the contents of the document related to it, and it's still not placing the markers after.
I'd appreciate a lot your suggestions, thanks in advance.