我试着去寻找最近的用户是在线的每个用户, 这是我的火力点数据库(geofire的想法?):发现使用火力nearst用户
这是我MainActivity
onCreate
功能这是越来越的数据:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// Set default username is anonymous.
mUsername = ANONYMOUS;
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
// Initialize Firebase Auth
mFirebaseAuth = FirebaseAuth.getInstance();
mFirebaseUser = mFirebaseAuth.getCurrentUser();
if (mFirebaseUser == null) {
// Not signed in, launch the Sign In activity
startActivity(new Intent(this, SignInActivity.class));
finish();
return;
} else {
mUsername = mFirebaseUser.getDisplayName();
if (mFirebaseUser.getPhotoUrl() != null) {
mPhotoUrl = mFirebaseUser.getPhotoUrl().toString();
}
}
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API)
.addApi(AppInvite.API)
.build();
setContentView(R.layout.activity_user_profile);
Firebase.setAndroidContext(this);
gpsTracker = new GPSTracker(MainActivity.this);
double lat = gpsTracker.getLatitude();
double lang = gpsTracker.getLongitude();
mDatabase = FirebaseDatabase.getInstance().getReference();
mAuth = FirebaseAuth.getInstance();
mDatabase.child("User").child(mAuth.getCurrentUser().getUid()).child("latitude").setValue(lat);
mDatabase.child("User").child(mAuth.getCurrentUser().getUid()).child("longitude").setValue(lang);
mDatabase.child("User").child(mAuth.getCurrentUser().getUid()).child("Availability").setValue(true);
mDatabase.child("User").child(mAuth.getCurrentUser().getUid()).child("Availability").onDisconnect().setValue(false);
FirebaseOptions options = new FirebaseOptions.Builder().setApplicationId("geofire").setDatabaseUrl(GEO_FIRE_DB).build();
FirebaseApp app = FirebaseApp.initializeApp(this, options);
// setup GeoFire
this.geoFire = new GeoFire(FirebaseDatabase.getInstance(app).getReferenceFromUrl(GEO_FIRE_REF));
}
我在Android开发新的,这是我第一次真正的应用程序,我的下一个任务是使用存储在数据库中,这样每个用户CA信息ñ与最近的用户联系。我该怎么做?我想创建与用户的所有距离的散列,并通过SharedPreferences
保存在用户。
请帮帮我。 非常感谢。
既然你已经考虑使用GeoFire的,我建议您查看文档:https://github.com/firebase/geofire-java#getting-started-与-火力点。它会告诉你如何[将用户插入到Geoindex中](https://github.com/firebase/geofire-java#setting-location-data)(实际上这只是Firebase数据库中的一个单独的节点,它具有用户键和Geohash)以及如何[查询附近的用户](https://github.com/firebase/geofire-java#geo-queries)。 –