Adit Luhadia
Adit Luhadia

Reputation: 412

How to query nearest geopoints in Firestore for a Flutter app?

I am working on an app which can show 5-10 nearest GeoPoints from Firestore database for a Flutter app. Is it possible to do this in the Flutter app itself or should I make a Firebase cloud function? How do I query the nearest GeoPoints?

Upvotes: 1

Views: 1490

Answers (1)

Nibrass H
Nibrass H

Reputation: 2497

There are 2 ways to do a query nearest geopoints in Firebase Database for a Flutter app.

  1. GeoFlutterFire
  2. Firestore Helpers

You can have a look into the following code to have an idea of how to query nearest geopoints Using GeoFlutterFire :

// Create a geoFirePoint
GeoFirePoint center = geo.point(latitude: 19.9132, longitude: 72.623603);

// get the collection reference or query
var collectionReference = Firestore.instance.collection("MY_COLLECTION");
double radius = 50;
String field = 'position';

Stream<List<DocumentSnapshot>> stream = geo.collection(collectionRef: 
       collectionReference).within(center: center, radius: radius, field: field);

Upvotes: 2

Related Questions