I have a function that retrieves map markers from a RAW file that was hosted on GitHub.
Now that I have the app finished, I was working on being able to do the same from the Firebase server, but haven't been able to figure out how to retrieve the information the same way as I did from a GitHub file.
This is the function that retrieves the map markers:
getStations() {
return fetch('https://raw.githubusercontent.com...')
.then(response => response.json())
.then(responseData => {
var markers = [];
for (var i = 0; i < responseData.features.length; i++) {
if (responseData.features[i].properties.Torwand != '<Null>') {
var coords = responseData.features[i].geometry.coordinates;
var obcn = responseData.features[i].properties.obcn;
var bikesToTake = responseData.features[i].properties.bikesToTake;
var spacesToLeft = responseData.features[i].properties.spacesToLeft;
var status = responseData.features[i].properties.status;
var marker = {
coordinate: {
latitude: coords[1],
longitude: coords[0],
},
title: obcn,
description: "Estado: " + status + " Bicicletas: " + bikesToTake + " Espacios: " + spacesToLeft
}
markers.push(marker);
}
}
this.setState({
markers: markers,
loaded: true,
});
}
).done();
}
My idea was to replace the RAW file URL from GitHub with something similar from Firebase, but the documentation is sparse and there is nothing about RAW files.
Good morning Christopher,
First you have to have the firebase package installed in your project.
https://yarnpkg.com/en/package/firebase
Now you have to have a project created in Firebase and a file in your project with the configuration, for example Firebase.js and inside the following code with your data.
https://firebase.google.com/
And do the initialization of the firebase I recommend that you do it in the app.js
Now we are going to imagine that we have a collection in firebase with the data from your file.json, we would simply have to execute the following line to get all the elements.
In this way you would get the entire collection.
All the best.