2

I am new with Firebase, Leaflet, and GeoJSON ..

I have a question, how to store data with GeoJSON format in Firebase, so it can be retrieved and used for leaflets GeoJSON to display marker(s). I know there is GeoFire library that allows me to store and query a set of keys based on their geographic location, but I want to use GeoJSON for some reason.

as i know if Firebase store the file as an object and GeoJSON as array, but is there any way? Please let me know.

  • Depends if you want to store markers/points, whole geojson feature collections or something else. Each spec has it's own format, so the method of creating each type will be different. – malcolm Sep 17 '16 at 14:44
2

TL;DR: yes you can, but why would you want to do this?

You can just upload GeoJSON using JSON file using Firebase console and it technically works. The data can then be loaded using REST API, and you will get same GeoJSON as result of .json query. However, this is not very effective as you can query same dataset back, or refer specific object by index (e.g. get first, second object etc). Then there is question why you would use Firebase for this, better then use some Geo-specific data storage, e.g. CartoDB, Github etc which has map visualisations etc.

Firebase Database is meant for real-time data, so good use case would be e.g. tracking device GPS locations (points with timestamps, based on user ID-s). This means that you need specific data structure to enable queries by user, time or location, stored GeoJSON does not give such possibilities, even after you have loaded it to the Firebase. That's why GeoFire uses a bit different structure: adds GeoHash keys to each object, so you use this as quick spatial filter and you can do location-based queries with this. Also you can add timestamp as key and query based on this range and probably you want to use user id as higher level key. With GeoFire data structure you can even subscribe to real-time location-based notifications (area entry/leave).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.