Back

Issue with Location-Based Document Retrieval

  • 0
  • Databases
  • Flutter
  • Cloud
arun
22 May, 2024, 19:50

I am encountering an issue while retrieving documents based on their location data within an Appwrite collection. I'm following the guidance provided in the forum thread (https://appwrite.io/threads/1132861274062082058 and https://levelup.gitconnected.com/building-a-location-based-app-with-appwrite-48a2e2b6d4c2#8e5c) but I'm not getting the expected results.

Current Situation: I have two documents in my collection with attributes named lat and lang containing the following latitude and longitude values: Document 1: lat - 13.030373668739, long - 77.750823773725 Document 2: lat - 14.030373668739, doc - 78.750823773725 I'm calculating bounds using the Bounds.getBounds function with a center point (Point(lng: 14.030373668738747, lat: 78.75082377372495)) and a specific distance (2 in this case). The constructed query uses these bounds to filter documents based on latitude and longitude:

_appwriteService.databases.listDocuments( databaseId: 'databaseID', collectionId:'collectionID', queries: [ Query.greaterThan('lat', location.south.lat), Query.lessThan('lat', location.north.lat), Query.greaterThan('long', location.west.lng), Query.lessThan('long', location.north.lng), ]);

Problem:

Despite the documents having location data within the calculated bounds, the query isn't returning any results.

I would appreciate your assistance in identifying the reason why the documents aren't being retrieved.
Is there a potential issue with the query construction or the bounds calculation? Any suggestions or troubleshooting steps would be greatly helpful.

TL;DR
Developers are trying to retrieve documents based on location data but facing issues despite having data within bounds. The issue might be with query construction or bounds calculation. Check permissions and ensure proper formatting of code.
Steven
22 May, 2024, 19:52

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting).

Steven
22 May, 2024, 19:53

sooo what did you get for the bounds?

Steven
22 May, 2024, 19:53

and what are the permissions on the collection and documents? are you able to get the documents without any filter queries?

arun
22 May, 2024, 19:57

Yes, without any query i am able to retrieve both documents

arun
22 May, 2024, 19:57

Here are the bounds : east: 78.75082377372495,13.288457667830574, north: 78.8955539432538,14.030373668738747, south: 78.60609360419609,14.030373668738747, west: 78.75082377372495,14.77228966964692

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more