如果没有创建 Geofire,我如何检查 Geofire 以注销用户?
How can I check Geofire to log user out if no Geofire was created?
问题总结: 我是 Android Studio 和 Firebase with Geofire 的新手,请多关照。我的目标是当用户在我的应用程序的地图屏幕上没有 Geofire 位置时注销用户。我不知道如何在我的 Geofire 中查询 "g"。如何查询 "g" 子节点以查看它是否已创建?如果未创建 "g",则需要注销它们。所以目标是查询 "g" 并创建方法,如果 "g" 为空,则将用户注销。
我做过的事情: 许多 Whosebug 帖子没有使用 Android Studio。我确实找到了这个 I have inserted location using geofire in firebase but it did not resolve my issue. I also tried
onLocationChanges 是我添加在线供应商的地方,也是我想检查是否已创建 "g" 的地方。
@Override
public void onLocationChanged(Location location) {
// Adds VendorOnline Child to Firebase when Vendor is On This Activity
addVendorOnline();
// Log user out if they are on the map screen without a "VendorOnline" Uid
logVendorOutIfBuggy();
}
这是创建在线商贩并检查是否已创建"g"的方法:
private void addVendorOnline(){
if (FirebaseAuth.getInstance().getCurrentUser() != null) {
String vendorId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference vendorIdReference = FirebaseDatabase.getInstance().getReference("VendorOnline");
GeoFire vendorGeoFire = new GeoFire(vendorIdReference);
vendorGeoFire.setLocation(vendorId, new GeoLocation(lastLocation.getLatitude(), lastLocation.getLongitude()));
}
}
// Log user out if for some reason they do not have a "g" child but are on the map screen.
private void logVendorOutIfBuggy() {
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("g");
if(ref == null){
Toast.makeText(VendorMapsActivity.this, "Error", Toast.LENGTH_LONG).show();
FirebaseAuth.getInstance().signOut();
}
我期望发生的事情和实际发生的事情: 如果 "g" 等于 null,我希望用户注销,但现在用户不退出。
这是调用 getLocation
以查看供应商是否注册了位置的示例。
来自 LocationCallback.onLocationResult
的 javadocs :
This method is called with the current location of the key. location
will be null if there is no location stored in GeoFire for the key.
final String vendorKey = "someVendorKey";
geoFire.getLocation(vendorKey, new LocationCallback() {
@Override
public void onLocationResult(String key, GeoLocation location) {
if (key.compareTo(vendorKey) == 0) {
if (location == null) {
// vendor has not logged a location yet (or it was removed)
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
问题总结: 我是 Android Studio 和 Firebase with Geofire 的新手,请多关照。我的目标是当用户在我的应用程序的地图屏幕上没有 Geofire 位置时注销用户。我不知道如何在我的 Geofire 中查询 "g"。如何查询 "g" 子节点以查看它是否已创建?如果未创建 "g",则需要注销它们。所以目标是查询 "g" 并创建方法,如果 "g" 为空,则将用户注销。
我做过的事情: 许多 Whosebug 帖子没有使用 Android Studio。我确实找到了这个 I have inserted location using geofire in firebase but it did not resolve my issue. I also tried
onLocationChanges 是我添加在线供应商的地方,也是我想检查是否已创建 "g" 的地方。
@Override
public void onLocationChanged(Location location) {
// Adds VendorOnline Child to Firebase when Vendor is On This Activity
addVendorOnline();
// Log user out if they are on the map screen without a "VendorOnline" Uid
logVendorOutIfBuggy();
}
这是创建在线商贩并检查是否已创建"g"的方法:
private void addVendorOnline(){
if (FirebaseAuth.getInstance().getCurrentUser() != null) {
String vendorId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference vendorIdReference = FirebaseDatabase.getInstance().getReference("VendorOnline");
GeoFire vendorGeoFire = new GeoFire(vendorIdReference);
vendorGeoFire.setLocation(vendorId, new GeoLocation(lastLocation.getLatitude(), lastLocation.getLongitude()));
}
}
// Log user out if for some reason they do not have a "g" child but are on the map screen.
private void logVendorOutIfBuggy() {
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("g");
if(ref == null){
Toast.makeText(VendorMapsActivity.this, "Error", Toast.LENGTH_LONG).show();
FirebaseAuth.getInstance().signOut();
}
我期望发生的事情和实际发生的事情: 如果 "g" 等于 null,我希望用户注销,但现在用户不退出。
这是调用 getLocation
以查看供应商是否注册了位置的示例。
来自 LocationCallback.onLocationResult
的 javadocs :
This method is called with the current location of the key. location will be null if there is no location stored in GeoFire for the key.
final String vendorKey = "someVendorKey";
geoFire.getLocation(vendorKey, new LocationCallback() {
@Override
public void onLocationResult(String key, GeoLocation location) {
if (key.compareTo(vendorKey) == 0) {
if (location == null) {
// vendor has not logged a location yet (or it was removed)
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});