0

I am taking input from user to get place detail by using autocomplete place api offered by Google.

Now I want to get each document from Firestore which belongs to this place. So to do this what approach should I follow? What should I store in documents so I can easily find it out.

My approach

   myShopsCollection
           shopDoc1
              city:"xyz"
              arrayId:[placeId1,PlaceId2,PlaceId3]
           shopDoc2
                  ....

Now I get placeId PID from autocomplete api my query become like this

db.collection(myShopsCollection').where('arrayId','array-contains',PID)
user7411343
  • 163
  • 1
  • 1
  • 9
  • What have you tried so far? – Alex Mamo Jan 22 '19 at 11:58
  • I thought I should store placeIds in array to in each document then get placeId from Place api and get documents if array contains this placeId – user7411343 Jan 22 '19 at 12:01
  • But problem is that onle place can have multiple placeId – user7411343 Jan 22 '19 at 12:02
  • Can you sketch what you have in mind? – Alex Mamo Jan 22 '19 at 12:04
  • @ AlexMamo I have updated my question please check it out – user7411343 Jan 22 '19 at 12:20
  • You should store location lat-long in GeoPoint data type and filter the data on the basis of distance. – Ishant Jan 22 '19 at 12:27
  • Your approach looks feasible to me. What is the issue? – Alex Mamo Jan 22 '19 at 12:29
  • @alexaMamo problem is that one place can have multiple placeId.so if placeId got from autocomplete api may have differ from which i have stored in shopDoc for same place – user7411343 Jan 22 '19 at 12:51
  • @Ishant If you search some thing in big area like whole delhi and shopDoc store Geopoint for their location( belongs to delhi) then how you calculate distance ? – user7411343 Jan 22 '19 at 12:58
  • Geoqueries are not natively implement in Firestore yet, but some developers have implemented their own "nearby queries" on top of it. See https://stackoverflow.com/questions/46630507/how-to-run-a-geo-nearby-query-with-firestore, my video here: https://www.youtube.com/watch?v=mx1mMdHBi5Q and this shorter tutorial: https://angularfirebase.com/lessons/geolocation-query-in-firestore-realtime/ – Frank van Puffelen Jan 22 '19 at 14:41

0 Answers0