mercredi 8 juillet 2020

My location is updating without me moving using altbeacon android studio

I have a strange problem.My location is updating without me moving and distance from my phone to other beacons is changing also without me moving . Here is where my location is initially calculated:

public void onBeaconServiceConnect() {
        RangeNotifier rangeNotifier = new RangeNotifier() {
            @Override
            public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
                int beacon_number = beacons.size();
              Beacon[] beacon_array = beacons.toArray(new Beacon[beacons.size()]);
                Beacon device1 = null, device2 = null, device3 = null;
                Constants constants = new Constants();
                double RSSI1Unfiltered = 0;
                float txPow1 = 0;
                double RSSI2Unfiltered = 0;
                float txPow2 = 0;
                double RSSI3Unfiltered = 0;
                float txPow3 = 0;
                if (beacon_number == 3) {
                 //Beacon[] beacon_array = beacons.toArray(new Beacon[beacons.size()]);
                    if (beacon_array[0].getIdentifier(0).toString().equals(Constants.DEVICE1_UUID))    {
                        device1 = beacon_array[0];
                        Log.d(TAG,"NOW I AM TAKING VALUE FOR DEVICE1 = BEACON ARRAY 0 ");
                    }  else  if (beacon_array[1].getIdentifier(0).toString().equals(Constants.DEVICE1_UUID)) {
                        device1 = beacon_array[1];
                        Log.d(TAG,"NOW I AM TAKING VALUE FOR DEVICE1 = BEACON ARRAY 1 ");
                    }   else {
                        device1 = beacon_array[2];
                        Log.d(TAG,"NOW I AM TAKING VALUE FOR DEVICE1 = BEACON ARRAY 2 ");
                    }
                     if (beacon_array[0].getIdentifier(0).toString().equals(Constants.DEVICE2_UUID)) {
                            device2 = beacon_array[0];
                            Log.d(TAG,"NOW I AM TAKING VALUE FOR DEVICE2 = BEACON ARRAY 0 ");
                    }  else  if (beacon_array[1].getIdentifier(0).toString().equals(Constants.DEVICE2_UUID)) {
                        device2 = beacon_array[1];
                        Log.d(TAG,"NOW I AM TAKING VALUE FOR DEVICE2= BEACON ARRAY 1 ");
                    }    else {
                        device2 = beacon_array[2];
                        Log.d(TAG,"NOW I AM TAKING VALUE FOR DEVICE2 = BEACON ARRAY 2 ");

                    }
                     if (beacon_array[0].getIdentifier(0).toString().equals(Constants.DEVICE3_UUID)) {
                         device3 = beacon_array[0];
                         Log.d(TAG,"NOW I AM TAKING VALUE FOR DEVICE3 = BEACON ARRAY 0");
                     }  else  if (beacon_array[1].getIdentifier(0).toString().equals(Constants.DEVICE3_UUID)){
                         device3 = beacon_array[1];
                         Log.d(TAG,"NOW I AM TAKING VALUE FOR DEVICE3 = BEACON ARRAY 1 ");
                     }   else {
                         device3 = beacon_array[2];
                         Log.d(TAG,"NOW I AM TAKING VALUE FOR DEVICE3 = BEACON ARRAY 2 ");
                     }
                        RSSI1Unfiltered = device1.getRssi();
                        RSSI2Unfiltered = device2.getRssi();
                        RSSI3Unfiltered = device3.getRssi();

                        txPow1 = device1.getTxPower();
                        txPow2 = device2.getTxPower();
                        txPow3 = device3.getTxPower();

                        double dis1 = locationFinder.calculateDistance(txPow1,RSSI1Unfiltered);
                        double dis2 = locationFinder.calculateDistance(txPow2,RSSI2Unfiltered);
                        double dis3 = locationFinder.calculateDistance(txPow3,RSSI3Unfiltered);

                        Log.d(TAG, "TxPower of " + beacon_array[0].getIdentifier(0) + "is " + txPow1 + " and RSSI is : " + RSSI1Unfiltered + " and is at " + dis1 + "   " + device1.getIdentifier(0));
                        Log.d(TAG, "TxPower of " + beacon_array[1].getIdentifier(0) + "is " + txPow2 + " and RSSI is : " + RSSI2Unfiltered + " and is at " + dis2 + " " + device2.getIdentifier(0));
                        Log.d(TAG, "TxPower of " + beacon_array[2].getIdentifier(0) + "is " + txPow3 + " and RSSI is : " + RSSI3Unfiltered + " and is at " + dis3 + " " + device3.getIdentifier(0));

                        RunningAverageRssiFilter.setSampleExpirationMilliseconds(3000l);

                         //pass location!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                          center = locationFinder.findLocation(RSSI1Unfiltered, txPow1, RSSI2Unfiltered, txPow2, RSSI3Unfiltered, txPow3);

                          sendCurrentLocation(center);

                          Log.d(TAG, "beacon in reagion" + beacons.size());

                          Log.d(TAG, "Current coordinates: asta e asta e !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " + center.toString());

             }

Here I am calculating my position and the logcat for this is something like this : Logcat for this

I think this class is also useful to show :

public class Constants {

    
    public static final LatLng DEVICE1_COORDINATES = new LatLng(47.686192, 22.479419);
    public static final String DEVICE1_UUID = "330d6309-e7b1-42f0-a7d5-0306c1ea1d69";


    public static final LatLng DEVICE2_COORDINATES = new LatLng(47.686174,22.479376);
    public static final String DEVICE2_UUID = "f159a8d4-2a61-4a66-b61a-da84353ad9d6";

  
    public static final LatLng DEVICE3_COORDINATES = new LatLng(47.686141,22.479448 );
    public static final String DEVICE3_UUID = "4cc54d62-2403-443b-89b6-2282490ab3c0";

}

So my question is , the code is the problem or the beacon technology.

Aucun commentaire:

Enregistrer un commentaire