未调用java onLocationResult
我正在学习一个教程,我正在开发一个像Uber这样的应用程序。当有人以潜水员身份登录应用程序时,应调用onLocationResult方法,在该方法中,将驾驶员的记录放在名为DriversAvailable的firebase表中。出于某种原因,这个表没有在我的数据库中创建,我很确定这是因为没有调用onLocationResult方法。在我的onLocationResult方法中,一个名为customerID的变量上有一个开关,如果该变量为空,则将驱动程序的位置放置在DriversAvailable表中。在客户登录并单击“呼叫优步按钮”之前,customerID将为空。因此,当我使用两部手机测试此功能时,并且我以驾驶员身份登录时,我应该会在驾驶员中看到一条记录,驾驶员的位置为儿童
LocationCallback Callback = new LocationCallback(){
@Override
public void onLocationResult(LocationResult locationResult) {
for(Location location : locationResult.getLocations()){
if(getApplicationContext()!=null){
if(!customerID.equals("") && mLastLocation!=null && location != null){
rideDistance += mLastLocation.distanceTo(location)/1000;
}
mLastLocation = location;
LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference refAvailable = FirebaseDatabase.getInstance().getReference("DriversAvailable");
DatabaseReference refWorking = FirebaseDatabase.getInstance().getReference("DriversWorking");
GeoFire geoFireAvailable = new GeoFire(refAvailable);
GeoFire geoFireWorking = new GeoFire(refWorking);
switch (customerID){
case "":
geoFireWorking.removeLocation(userId);
geoFireAvailable.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()));
break;
default:
geoFireAvailable.removeLocation(userId);
geoFireWorking.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()));
break;
}
}
}
}
};
共 (0) 个答案