Triangulate example for iBeacons

后端 未结 13 2347
梦毁少年i
梦毁少年i 2020-11-28 17:14

I am looking into the possibility to use multiple iBeacons to do a \'rough\' indoor position location. The application is a kind of \'museum\' setting, and it would be easie

13条回答
  •  孤街浪徒
    2020-11-28 17:44

    For those who need @Javier Chávarri trilateration function for Android devices (for saving some time):

    public static Location getLocationWithTrilateration(Location beaconA, Location beaconB, Location beaconC, double distanceA, double distanceB, double distanceC){
    
        double bAlat = beaconA.getLatitude();
        double bAlong = beaconA.getLongitude();
        double bBlat = beaconB.getLatitude();
        double bBlong = beaconB.getLongitude();
        double bClat = beaconC.getLatitude();
        double bClong = beaconC.getLongitude();
    
        double W, Z, foundBeaconLat, foundBeaconLong, foundBeaconLongFilter;
        W = distanceA * distanceA - distanceB * distanceB - bAlat * bAlat - bAlong * bAlong + bBlat * bBlat + bBlong * bBlong;
        Z = distanceB * distanceB - distanceC * distanceC - bBlat * bBlat - bBlong * bBlong + bClat * bClat + bClong * bClong;
    
        foundBeaconLat = (W * (bClong - bBlong) - Z * (bBlong - bAlong)) / (2 * ((bBlat - bAlat) * (bClong - bBlong) - (bClat - bBlat) * (bBlong - bAlong)));
        foundBeaconLong = (W - 2 * foundBeaconLat * (bBlat - bAlat)) / (2 * (bBlong - bAlong));
        //`foundBeaconLongFilter` is a second measure of `foundBeaconLong` to mitigate errors
        foundBeaconLongFilter = (Z - 2 * foundBeaconLat * (bClat - bBlat)) / (2 * (bClong - bBlong));
    
        foundBeaconLong = (foundBeaconLong + foundBeaconLongFilter) / 2;
    
        Location foundLocation = new Location("Location");
            foundLocation.setLatitude(foundBeaconLat);
            foundLocation.setLongitude(foundBeaconLong);
    
        return foundLocation;
    }
    

提交回复
热议问题