【发布时间】:2016-01-01 05:49:15
【问题描述】:
我正在尝试将我的移动设备 (s6-android 5.1) 与硬件 IBeacon 保持正确的距离。
首先以这种形式开始:
protected void onCreate(Bundle savedInstanceState) {
...
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager
.getBeaconParsers()
.add(new BeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
beaconManager.bind(this);
...
}
然后覆盖这个:
@Override
public void onBeaconServiceConnect() {
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
Log.i(TAG + "region", region.toString());
Log.i(TAG + " Size ", String.valueOf(beacons.size()));
for (Beacon beacon : beacons) {
Log.i(TAG, " Distance :" + beacon.getId1() + ", " + beacon.getId2() + ", " + beacon.getId3());
}
if (beacons.size() > 0) {
Beacon firstBeacon = beacons.iterator().next();
logToDisplay("The first beacon " + firstBeacon.toString() + " is about " + firstBeacon.getDistance() + " meters away.");
Log.i(TAG + " Distance ", beacons.iterator().next().getDistance() + "");
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("RadBeacon",
Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"),
Identifier.parse("1"), Identifier.parse("1")));
} catch (RemoteException e) {
Log.i(TAG + "Error", e.toString());
}
}
在顶级方法中,我可以登录 region 正确返回:
id1: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6 id2: 1 id3: 1
Log中的其他信息:
onScanResult() - ScanResult{mDevice=....., mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=null, mManufacturerSpecificData={76=[2, 21, -30, -59, 109, -75, -33, -5, 72, -46, -80, 96, -48, -11, -89, 16, -106, -32, 0, 2, 0, 6, -59]}, mServiceData={00005153-0000-1000-8000-00805f9b34fb=[67]}, mTxPowerLevel=0, mDeviceName=null], mRssi=-60, mTimestampNanos=431625881888515}
但我的问题是Collection<Beacon> beacons,这总是返回 0
我也可以通过Monitor进入/退出区域:
beaconManager.setMonitorNotifier(new MonitorNotifier() {...}
但仍无法获取移动设备和 Beacon 硬件之间的距离;
所以在更多搜索之后找到一种方法并尝试:
protected static double calculateAccuracy(int txPower, double rssi) {
if (rssi == 0) {
return -1.0; // if we cannot determine accuracy, return -1.
}
double ratio = rssi * 1.0 / txPower;
if (ratio < 1.0) {
return Math.pow(ratio, 10);
} else {
return (0.89976) * Math.pow(ratio, 7.7095) + 0.111;
}
}
对于 rssi ,设置 mRssi 给出 Log 和 txPower 设置 Static int ,但 return value 不正确。
现在我有两个问题:
- 为什么
Collection<Beacon> beacons总是返回0值? - cat 如何在移动设备和 Ibeacon 硬件之间实现正确的
Distance?
在我尝试这个库和资源之前:
https://forums.estimote.com/t/get-distance-of-beacons/1986
Measure distance to iBeacon from Android device
https://github.com/AltBeacon/android-beacon-library/issues/43
https://github.com/NickdeDycker/EstimoteIndoorAndroid
http://altbeacon.github.io/android-beacon-library/samples.html
http://developer.estimote.com/android/tutorial/part-3-ranging-beacons/
还有许多其他链接!
Thank you for your attention and help
编辑1
它在Logcat 中显示:
W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device. Using default
@davidgyoung
【问题讨论】:
标签: android ibeacon ibeacon-android altbeacon