firebase / geofire-js

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

Polygon shaped geoqueries #46

Open sauravbiswasiupr opened 10 years ago

sauravbiswasiupr commented 10 years ago

What about support for polygon based geoQueries ? The current API seems to provide support only for circular geoQueries.

jwngr commented 10 years ago

Hey @sauravbiswasiupr, mind sharing your use case? We have considered adding rectangular GeoQueries but didn't think there was enough demand for them. I'm interested to hear your thoughts though.

jeffcjohnson commented 10 years ago

I too would like polygon search and not just rectangular. I want to draw a polygon around a specific neighborhood and find only data in that polygon for example.

Also I would think rectangular search would be needed in the vast majority of apps that simply want to display data on the current map which is always rectangular.

If polygon search is too hard I could try using https://github.com/firebase/flashlight for polygon search but would much prefer geofire.

sauravbiswasiupr commented 10 years ago

Hi @jwngr , sorry for the late reply. Basically consider searching for some location ( lat, lon) that lies inside a polygon of n sides, where n is a finite number. Like @jeffcjohnson mentioned, basically you could draw a polygon of n sides ( say 4 ) on the map, and get a list of vehicles ( or data that you might have stored), in the callback. I think this feature would be pretty cool.

jwngr commented 10 years ago

Thanks for the feedback guys. Polygon-shaped geoqueries are going to be tricky! I think we will most likely implement rectangular geoqueries in the next major release, but I'm not sure exactly how we would implement arbitrary polygon queries. We will definitely need to go back to the drawing board on that one.

If this is really something you want to see, this is an open source project and I would be more than happy to review some code you submit. This is definitely not a small thing to add, but if you need it/want to see it, feel free to throw some code around. I can answer any questions about the code that you have.

I'll keep this issue open until we add some more query types.

cxz commented 9 years ago

I need to do polygon-based geoqueries too.

What do you think if we reduce this problem to:

jwngr commented 9 years ago

I think that kind of solution would work well in the average case. I unfortunately don't think I'll have a chance to implement this kind of functionality any time soon, but I would gladly review any PRs that come my way.

stevepepple commented 9 years ago

Here's an example of how to use Turf.js for reducing a query to a rectangle or polygon shape. Seems like this technique would work well in the Geofire library: http://s.codepen.io/stevepepple/debug/ByVyYX?

Another option would be to take the area of your polygon (or the "extent" of the feature) and create a circle (query) around it.

gigablox commented 9 years ago

You guys are talking about a Ray-Casting algorithm found in Google Maps JS API - aka "point in polygon". I agree a feature like this would be absolutely killer.

https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation

adamduren commented 8 years ago

:+1:

steffenfrost commented 8 years ago

@gigablox , great suggestion.

Hi @jwngr , we are urrently at the Launch Hackathon, and we could use this feature. Can't you go visit your Google Maps colleagues and ask them how to do it? There a many geodata application which could use this feature.