firebase / geofire-js

GeoFire for JavaScript - Realtime location queries with Firebase
MIT License
1.45k stars 346 forks source link

Internal State error, trying to remove location that is still in query #133

Open Youdaman opened 7 years ago

Youdaman commented 7 years ago

Took me a while to reproduce this on the example, but here's a screenshot:

screenshot 2017-01-30 21 40 26

To reproduce, visit https://geofire.firebaseapp.com/queryBuilder/index.html and create a fish with latlng 34.0489281,-111.09373110000001 then create a query with radius 10000 and latlng 43.92630646953202,127.05690366562499 then update the query with latlng 43.16183777054158,-116.57590883437501 and then revert it back to latlng 43.92630646953202,127.05690366562499 and update it few times and it throws the error:

"Internal State error, trying to remove location that is still in query"

Now my wild guess as to why this happens is that the earth has a diameter of 12742km and so the biggest search radius should be half that. I tried drawing a circle on Google Maps and with the same radius as the query and depending where the center is and how far you're zoomed out you get a sine wave as opposed to a circle, and so I can only guess that when the search radius is too big you end up with an "overlap" or maybe a situation where a key is both in and out of the search circle at the same time. Again, this is only a guess.

I'd love a way to overcome this problem, and my current "solution" is based on my wild guess where I limit the size of the query radius to 6371km (half the diameter of the world to avoid circle overlap).

Youdaman commented 7 years ago

Another related question, is it possible to search via the northeast/southwest bounding coordinates instead of a radius? This would make more sense when using GeoFire with a map.

Currently I'm grabbing the center of the map, then one of the corners and then using the distance between those two points as the radius of my search query -- with the only problem being needing to manually filter out results that are outside the borders of the map but still within the query circle.

I think CouchDB has some geo stuff that uses a bounding box instead of a circle?

mb040574 commented 7 years ago

Was anything done to this bug??

kasterlod commented 6 years ago

query radius to 6371km but still getting error. I temporarily hide this error throwing (and works!) but in the near future I will try to find solution (https://github.com/kasterlod/geofire-js)

Fab-z4qx commented 6 years ago

I have this error too, even if the radius is < 6000km.

@kasterlod how did you catch this exception ?

filipef101 commented 6 years ago

bump

filipef101 commented 6 years ago

facing the same, any solution?

jfhidakatsu commented 6 years ago

I've had this problem as well at radius 6000. I put it down to radius 5000 and so far, I haven't seen the problem again.

jfhidakatsu commented 6 years ago

I think I finally solved this issue in my case, though this may or may not apply to other cases. For me, it was simply because I didn't call cancel on the geoquery (not just onKeyEntered type calls, but the entire query like geoquery.cancel()). My use case was using geoquery in a firebase cloud function, and GeoFire was still trying to do things after the function finished.