Closed LoneRifle closed 4 years ago
Thank you very much for your feedback! Yes we agree external libraries might help with the postcode filtering. We will look into this when we have bandwidth after getting more features implemented!
If we can agree on where the GeoPoint field should go in each entry in hawkers
, I can come up with the data update script and the PR
Thanks so much! We appreciate your help with this. For the GeoPoint field, perhaps we can add it as another property called "geopoint" under each entry? I'm not familiar with GeoFireX so I'm not sure if there are any other special requirements.
I am not sure if firebase allows select statement queries. If yes, you can use something like this
3959 * acos( cos( radians( ENTER_USER_LAT_HERE ) ) * cos( radians( ENTER_HAWKER_LAT_HERE ) ) * cos( radians( ENTER_HAWKER_LNG_HERE ) - radians( ENTER_USER_LNG_HERE ) ) + sin( radians( ENTER_USER_LAT_HERE ) ) * sin( radians( ENTER_HAWKER_LAT_HERE ) ) ) ) AS distance
All you need here is:
The result of above in an SQL statement will give you the distance between the current user and each hawker stall. Based on that distance you can sort in ascending order and the listing will have hawker stalls from nearest to furthest away from the user's postal code entered.
That way you won't have to use an additional library to achieve location search. Hope that helps.
Firebase doesn't allow sql style queries. I'll come up with something later today. In brief, I propose to add two additional fields alongside existing ones, and make the app use those new fields for querying.
Thanks @mervintankw and @LoneRifle, appreciate the help here :)
Migration script found here. Dump this into a new empty directory, run npm install
, inspect it so that you understand what it does, take a backup of your data, then plug in your Firebase config and invoke it.
https://gist.github.com/LoneRifle/6bd4921975c76e038b59d6d1765879be
Okay! I’ll try running it tonight when we have lower traffic.
Got caught up with some homework last night... will try again tonight/tomorrow
@LoneRifle I've run your script which added the location field. Now left with the GeoFireX implementation :) sorry it took a bit, had some fires to fight on the PR end...
I'll need an index created as detailed in this link: https://console.firebase.google.com/v1/r/project/hawkercentral/firestore/indexes?create_composite=Ck1wcm9qZWN0cy9oYXdrZXJjZW50cmFsL2RhdGFiYXNlcy8oZGVmYXVsdCkvY29sbGVjdGlvbkdyb3Vwcy9oYXdrZXJzL2luZGV4ZXMvXxABGhEKDXBpY2t1cF9vcHRpb24QARoVChF1bmRlZmluZWQuZ2VvaGFzaBABGgwKCF9fbmFtZV9fEAE
EDIT: Not needed anymore, unless you want your search to be better refined. I don't think it's really necessary
For a given postcode, the current iteration of the app does the following:
This may result in fewer entries than desired being returned to the user, as not everything returned would be within the threshold.
This issue proposes the use of GeoFireX to retrieve entries within a certain geographic radius. In short, GeoFireX determines proximity through multiple queries against entries that contain geohashes.
Note that this would require a Firebase-wide update to your data.
Further reading: https://fireship.io/lessons/geolocation-query-in-firestore-realtime/