MichaelSolati / geofirestore-js

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

Getting distance null in the return object #131

Closed shekhars-realm closed 5 years ago

shekhars-realm commented 5 years ago

here is the return object:

[ { exists: true, id: 'VXgVXlvwLVXAFKDifcOKq', data: [Function: data], distance: null } ]

Any possible reasons!

MichaelSolati commented 5 years ago

Can I see your query? If it isn't a geoquery then distance will be null.

shekhars-realm commented 5 years ago

sure.

geofirestore.collection('events').near({ center: new admin.firestore.GeoPoint(49.444231, 7.699167), radius: 1.5 }).get().then(data => { console.log('data: ',data.docs); })

the data structure is same as suggested in the docs.

MichaelSolati commented 5 years ago

The distance should work just fine, I created a sample stackblitz example showing how to access distance here => https://stackblitz.com/edit/geofirestore-distance

I'd advise starting to look at line 32, and if your code looks like that and still doesn't work then it is likely an issue with how the data is stored. Geofirestore works with data added to a collection by geofirestore, so it's good to be familiar with what that looks like.

Screen Shot 2019-07-29 at 3 34 27 PM

Since I can not replicate this, I'm closing the issue, however if you can provide sample code and a screenshot example of a document in a collection we can go from there!

MichaelSolati commented 5 years ago

PS, the distance will be null if the l field is not a proper GeoPoint. While you never see the g or l, only the content of the d, geofirestore needs them to work properly.

shekhars-realm commented 5 years ago

Hey, sorry for the later reply.

I guess there is some problem in the way I am storing the data:

firebase

shekhars-realm commented 5 years ago

I am using l for sorting the data, not locationString

Todmy commented 4 years ago

For me distance returns as null if I didn't set radius property