Geocoding processing in Firebase?

Has anyone tried to store and / or search on geocodes (e.g. lat / long) in Firebase? This is the functionality built into MongoDB, and since I am considering using Firebase for our backend instead, I need to know how I will handle this script in Firebase.

Thanks!

+6
source share
2 answers

People at Firebase recently opened a library that allows you to store and query location data on Firebase. In short, this is very easy to implement, because all keys in Firebase are strings, and Firebase supports startAt() and endAt() , which allows you to make appropriate windows for geo-hast and bounding rectangles.

For details and use of the implementation, check out live demos , the source code and their blog post on GeoFire.

+7
source

Hey, I just finished creating a Google map in real time using firebase and GeoFire. GeoFire is really cool and easy to use. It allows you to query using lon lat and radius. It returns a key that you can use to query your firebase database. You set the key while you create the geoFire object to be what you want. This is usually a link that you can use to get the object associated with this distance.

Here is the link to geoFire: https://github.com/firebase/geofire-js

Here is a usage example:

You have lon lat, which you use with the navigator:

 var lon = '123.1232'; var lat = '-123.756'; var user = { name: 'test user', longitude: lon, latitude: lat } usersRef.push(user).then(function(response) { var key = response.key; var coords = [lon, lat]; geoFire.set(key, coords, function(success){ console.log('User and geofire object has been created'); }); }) 

Now you can query the user using:

 // Set your current lon lat and radius var geoQuery = geoFire.query({ center: [latitude, longitude], radius: radiusKm }); geoQuery.on('key_entered', function(key, location, distance) { // You can now get the user using the key var user = firebaseRefUrl + '/' + key; // Here you can create an array of users that you can bind to a scope in the controller }); 

If you use google maps. I recommend you use angular -google-maps. This is a really cool Google Maps directive that uses an array of markers and circles. Therefore, when the variables $ scope.markers or $ scope.circles change in the controller, it will automatically be applied to the map without any dirty code. They have very good documentation.

Here is the link: http://angular-ui.imtqy.com/angular-google-maps/

0
source

All Articles