What is the recommended way of updating geolocation while preserving associated data?
See original GitHub issueI have the following structure:
I would like to update the location, while preserving the data
There is GeoFire.set(key, location)
https://github.com/firebase/geofire-js#geofiresetkey-location
But when I call it the data
would be lost.
I think I’ve found a workaround but it doesn’t seem very intuitive to me:
firebaseRef.child('data').once('value', function(snap) {
var data = snap.val();
geofire.set(name, [lat, long]).then(function() {
firebaseRef.child('data').set(data);
}, function(error) {
console.log('Error: ' + error);
});
});
- Saving data locally
- Updating geofire
- Storing data back to Firebase
Seem like a lot of work. Is there a better way?
Video explanation: https://www.youtube.com/watch?v=i5u77q7l8dU
You data sets are updating niceely: https://publicdata-transit.firebaseio.com/sf-muni 😃
Thanks!
Issue Analytics
- State:
- Created 9 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
How to Comply with Geolocation Data Privacy Regulations
It's true that there are many different laws governing how geolocation data can be collected, processed, and shared. And though these ...
Read more >How to Navigate Geolocation and Data Protection Laws
Update your privacy policies to include geolocation collection practices. ... Under most privacy laws and regulations, consumers have the right to know how...
Read more >The Power of Place: Geolocation Tracking and Privacy
[5] Aggregated location data (i.e., data that is identifiable by distinct data location points but not by individual) can help urban planners alleviate...
Read more >Getting the current location of a device - Apple Developer
The Significant-change location service offers a low-power way to get location updates. This service uses the cellular and Wi-Fi radios (not GPS) to...
Read more >Request location updates - Android Developers
Appropriate use of location information can be beneficial to users of your app. For example, if your app helps the user find their...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @stefek99 - The issue here is that GeoFire doesn’t support storing data inside of its index. Instead, you should store that information elsewhere, for multiple reasons. First, let me talk about what the solution here is. You should structure your data like this:
Note that the keys used for GeoFire are just the push IDs from the
/locations/
node. This is important because when you receive akey
from akey_entered
orkey_exited
event, you can easily use it to look up the data by doing arootRef.child("locations").child(key).once("value")
.Now, what is the benefit of doing it this way? For one, this is the only way that really works with GeoFire. Doing what you are trying to do and hack your own solution into the GeoFire index itself is probably not going to work. You don’t have enough control over that.
Also, it’s important to realize that there is often a difference in security between your GeoFire index and your data. If you store them all together, you can’t separate their security rules. And since the GeoFire needs to be pretty open to work properly, that would mean your secure location data would also need to be open. Separating them allows you to give them separate security rules.
Finally, not including your data in the GeoFire index reduces the amount of data going across the wire. If you stored all that data in the index, every time a location moved would result in a lot of wasted bytes. If you do what I suggested, you would only load data that you actually need, when you need it.
You will notice our transit open data set is structured in exactly this way. The GeoFire index for it can be found here. If you look at that, you’ll see that the GeoFire keys (e.g.
lametro:7869
) are a combination of the transit provider and bus ID. This allows us to easily look up bus info by doing aref.child(provider).child("vehicles").child(busId).once("value")
call. This is exactly what we do in our SF MUNI demo code.I’m going to close this issue but please feel free to respond if you still have questions.
Yes, you should look them up individually by ID. This does require 100 calls, but since we use a websocket which has already established an HTTPS connection, it should be fast. It’s not like you are making 100 HTTPS requests which are all opening connections to our server.