Adding additional children when setting in GeoFire Firebase?

旧巷老猫 提交于 2019-11-28 02:05:10

问题


I'm trying to set additional info when setting geoFire object in FB.

Something like:

geoFire.set(uniqueId, [latitude, longitude],{'message': message, 'iconUrl': iconURL, lastUpdate: Firebase.ServerValue.TIMESTAMP}).then(function () {
    //some stuff
};

I can do it like this and it mostly works (depends on db roundtrip time):

geoFire.set(uniqueId, [latitude, longitude],).then(function () {

    firebaseRef.child(uniqueId).update({'message': message, 'iconUrl': iconURL, lastUpdate: Firebase.ServerValue.TIMESTAMP});

    }) 

but my listener triggers too fast and doesn't capture all the data so it renders without icon path.


回答1:


I had the same problem, didn't want to solve this with a workaround, especially by introducing the delay so kept digging and found this: https://github.com/firebase/geofire-js/issues/40

This basically means we need to restructure the application, where one collection is dedicated to the GeoFire information, another uses the same key to store attached information. Example from the GitHub.

{
   geofire: {
      "-J9aZZl94Sx6h": { "g": <geohash>, "l": {} }
      "-Jhacf97x4S3h": { "g": <geohash>, "l": {} },
      ...
   },
   "locations": {
      "-J9aZZl94Sx6h": { <location-data> },
      "-Jhacf97x4S3h": { <location-data> }
   }
}


来源:https://stackoverflow.com/questions/26184918/adding-additional-children-when-setting-in-geofire-firebase

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!