I am designing a location based restaurant search application on android with firebase. Restaurant class as follows on firebase;
restaurants
-key
address: "NYC"
city: "New York"
description: ""
id: 60000
latitude: 39.895107
longitude: 32.797819
name: "Pizza Store"
Fragment class
mainActivity.mDatabase.child("restaurants").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
System.out.println("There are " + snapshot.getChildrenCount() + " restaurans");
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Restaurant post = postSnapshot.getValue(Restaurant.class);
mapmap2.put(post.getName(), postSnapshot.getKey());
restaurants.add(post);
}
adapter = new RestaurantCardViewAdapter(getActivity(), restaurants, MapListFragment.this);
mRecyclerView.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
Right now, I can list all the restaurants. But I want to query on user location. Firstly I want to list 20 restaurants near to user location and when user loads page through I want to get next 20 nearest restaurants. I do some search on internet. I found GeoFire library but as I understand its working with the legacy version of firebase. How can I query with these criterias?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…