I'm trying to find a way to compare the location of all users and show nearby people as a result. In this question, Frank explains how it should be done. But I have no idea how to do the third step.
That's what I've achieved so far:
double _userLatitude;
double _userLongitude;
_getUserLocation() async {
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
_userLatitude = position.latitude;
_userLongitude = position.longitude;
final firebaseUser = await FirebaseAuth.instance.currentUser();
if (firebaseUser != null)
await usersRef.document(firebaseUser.uid).updateData({
"location": "active",
"latitude": _userLatitude,
"longitude": _userLongitude,
});
}
_getNearbyUsers() {
usersRef.where('location', isEqualTo: "active").getDocuments();
Geolocator.distanceBetween(
_userLatitude, _userLongitude, endLatitude, endLongitude);
}
StreamBuilder(
stream: _getNearbyUsers(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: Text(
"Loading...",
),
);
} else if (snapshot.data.documents.length == 1) {
return Center(
child: Text(
":/",
),
);
}
return ListView.builder(
padding: EdgeInsets.only(top: 10),
scrollDirection: Axis.vertical,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) =>
_buildListUsers(context, snapshot.data.documents[index]));
},
),
Widget _buildListUsers(BuildContext context, DocumentSnapshot document) {
List<Users> usersList = [];
var data = document.data;
if (data["id"] != _userId) {
Users user = Users();
user.id = document["id"];
usersList.add(user);
return ListTile(
onTap: () {
Navigator.pushNamed(context, "/users", arguments: user);
},
title: Text(
document['id'],
),
);
}
return SizedBox();
}
I have no idea what to do next in _getNearbyUsers().