我試着去尋找最近的用戶是在線的每個用戶, 這是我的火力點數據庫(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)。 –