我无法删除地图上geofire关键出口上的标记



当任何驾驶员上网时,我正试图在地图上显示所有车辆所以使用geofire可以正常工作,但在删除时我无法删除地图上的clear地图正在被清除,但我不知道什么时候该清除地图才能使用asnk概念。

public static HashMap<String,Marker>  markers = new HashMap<>();
synchronized private static void findAllDriverInRadiusForUniqueVehicle(String 
selectedVehicleCategory, int limitKm, LatLng srcLocation,String callValue) {
Log.d(TAG, "findAllDriverInRadiusForUniqueVehicle: calling from = "+callValue);
//find driver in radius
GeoFire gf = new GeoFire(DR_DRIVER_LOC_TABLE.child(selectedVehicleCategory));
GeoQuery geoQuery = gf.queryAtLocation(new GeoLocation(srcLocation.latitude, srcLocation.longitude),limitKm);
geoQuery.removeAllListeners();
Log.d(TAG, "findAllDriverInRadiusForUniqueVehicle: driverLocation = " + DR_DRIVER_LOC_TABLE.child(Common.SELECTED_VEHICLE_CATEGORY));
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
Log.d(TAG, "onKeyEntered: i am starting near driver found at location = "+location+", key = "+key);
//use key to get the email of the users
Common.FOUND_DRIVER_LOCATION = location;
Common.driverId = key;
Common.isDriverFound = true;

progressBar.setVisibility(View.INVISIBLE);
txtProgress.setVisibility(View.INVISIBLE);

FirebaseDatabase.getInstance().getReference(Common.user_driver_tbl)  //user_rider_tbl
.child(key)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Common.FOUND_DRIVER_IN_LIMIT = dataSnapshot.getValue(Driver.class);
Log.d(TAG, "onDataChange: driver = " + Common.FOUND_DRIVER_IN_LIMIT + ", location = " + location);

if (Common.FOUND_DRIVER_IN_LIMIT != null) {

if (Common.FOUND_DRIVER_IN_LIMIT.getCarType().equalsIgnoreCase(selectedVehicleCategory)) {

// Adding new elements to the HashSet
Common.UNIQUE_VEHICLES.add(dataSnapshot.getKey());
Log.d(TAG, "onDataChange: Common.SELECTED_VEHICLE_CATEGORY = " + selectedVehicleCategory);
addDriverMarker(selectedVehicleCategory,Common.FOUND_DRIVER_IN_LIMIT.getName(), dataSnapshot.getKey(), location);
}

} else {
Common.isDriverFound = false;
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
Log.d(TAG, "onKeyEntered: i am exiting");
}
@Override
public void onKeyExited(String key) {

Log.d(TAG, "onKeyExited: driver has exited the radios or driver location is off key = "+key);

Log.d(TAG, "onKeyExited: removing marker key =  "+key);
markers.get(key).remove();   //here code is successfully executing but not removing
Log.d(TAG, "onKeyExited: removed marker key =  "+key);


Common.homeRadiusAll =Integer.parseInt(context.getString(R.string.home_distance));
findAllDriverInRadiusForUniqueVehicle(selectedVehicleCategory,Common.LIMIT,srcLocation,"2");

}
@Override
public void onKeyMoved(String key, GeoLocation location) {
Log.d(TAG, "onKeyMoved: ="+key);
}
@Override
public void onGeoQueryReady() {
Log.d(TAG, "onGeoQueryReady: is starting distance = " + Common.homeRadiusAll);
if (Common.homeRadiusAll <= Common.LIMIT) //distance just find for 3km
{
Log.d(TAG, "onGeoQueryReady if : distance = " + Common.homeRadiusAll);
}else{

}
Log.d(TAG, "onGeoQueryReady: is ending  ");
}
@Override
public void onGeoQueryError(DatabaseError error) {
Log.d(TAG, "onGeoQueryError: no driver found in given query");
}
});
Log.d(TAG, "loadAllAvailableDrivers:  Common.FOUND_DRIVER_LOCATION = "+ 
Common.FOUND_DRIVER_LOCATION);
}

这是addDriverMarker方法,使用这个方法我在地图上添加标记。

public static void addDriverMarker(String selectedVehicleCategory, String driverName, String 
driverKey, GeoLocation location) {
Common.DR_DRIVER_LOC_TABLE.child(selectedVehicleCategory)
.child(driverKey).child("l").
addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
MarkerOptions markerOptions  = new MarkerOptions()
.title(driverName)
.snippet("DRIVER ID : " + driverKey)
.flat(true)
.position(new LatLng(location.latitude, location.longitude)) 
.icon(BitmapDescriptorFactory.fromResource(R.drawable.car3));
marker =  Common.mHomeMap.addMarker(markerOptions); //here im adding marker and working
markers.put(driverKey, marker); //here adding to Hashmap
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
//i used everything but unable to delete particular marker from google map on android using java language.

试试这个

public void removeMarker(Marker marker) {
if (marker != null) {
marker.remove();            
}
}

您可以使用此方法从地图中删除标记列表

希望它能帮助你

相关内容

  • 没有找到相关文章

最新更新