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

问题描述 投票:0回答:1

我正在尝试在任何驾驶员上线时在地图上显示所有车辆所以使用geofire可以正常工作,但是在删除时我无法删除在地图上清除地图正在清除,但我不知道何时清除地图以使用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.
java android google-maps-markers geofire
1个回答
0
投票

尝试一下

© www.soinside.com 2019 - 2024. All rights reserved.