MichaelSolati / geofirestore-js

Location-based querying and filtering using Firebase Firestore.
https://geofirestore.com
MIT License
505 stars 58 forks source link

When querying `near`: `distance` prop is missing when distance is 0 #212

Closed mthomas-io closed 3 years ago

mthomas-io commented 3 years ago

[REQUIRED] Describe your environment

[REQUIRED] Describe the problem

When querying with near() using the the EXACT coordinates a document has, that returned doc is missing the distance property, while doc.distance should be 0. This is causing issues for me when sorting based on distance. Right now I resolve it by defaulting the distance to 0:

// When geocollection is queried with EXACT coordinates of a doc, that doc
// won't have a `distance` prop. Therefore we default the distance to 0.
result = result.sort((docA, docB) => (docA.distance || 0) - (docB.distance || 0));

Relevant Code

Will be able to create a Stackblitz later if necessary.

MichaelSolati commented 3 years ago

Sorry for the delay in responding, but are you including a radius in your query?

Separately here's a stackblitz showing that the distance is in the object (check the console in the preview).