我正在尝试开发一款用于测试Estimote信标的小型应用。我找到了与我的iPad完美运行的代码片段:显示房间中每个灯塔的uuid,major,minor和Proximity值。 但是' beacon.distance'命令返回" undefined"我的应用中的价值。有人可以告诉我为什么吗?
为了您的信息,我使用的是Jquery和PhoneGap Build平台。
提前THX! 干杯var app = (function()
{
var app = {};
var regions = [ {uuid:'B9407F30-F5F8-466E-AFF9-25556B57FE6D'} ];
var beacons = {};
var updateTimer = null;
app.initialize = function()
{
document.addEventListener('deviceready', onDeviceReady, false);
};
function onDeviceReady()
{
window.locationManager = cordova.plugins.locationManager;
startScan();
updateTimer = setInterval(displayBeaconList, 500);
}
function startScan()
{
var delegate = new locationManager.Delegate();
delegate.didRangeBeaconsInRegion = function(pluginResult)
{
for (var i in pluginResult.beacons)
{
var beacon = pluginResult.beacons[i];
beacon.timeStamp = Date.now();
var key = beacon.uuid + ':' + beacon.major + ':' + beacon.minor;
beacons[key] = beacon;
}
};
delegate.didStartMonitoringForRegion = function(pluginResult)
{
//console.log('didStartMonitoringForRegion:' + JSON.stringify(pluginResult))
};
delegate.didDetermineStateForRegion = function(pluginResult)
{
//console.log('didDetermineStateForRegion: ' + JSON.stringify(pluginResult))
};
locationManager.setDelegate(delegate);
locationManager.requestAlwaysAuthorization();
for (var i in regions)
{
var beaconRegion = new locationManager.BeaconRegion(
i + 1,
regions[i].uuid);
// Start ranging.
locationManager.startRangingBeaconsInRegion(beaconRegion)
.fail(console.error)
.done();
// Start monitoring.
// (Not used in this example, included as a reference.)
locationManager.startMonitoringForRegion(beaconRegion)
.fail(console.error)
.done();
}
}
function displayBeaconList()
{
$('#found-beacons').empty();
var timeNow = Date.now();
$.each(beacons, function(key, beacon)
{
if (beacon.timeStamp + 60000 > timeNow)
{
var rssiWidth = 1;
if (beacon.rssi < -100) { rssiWidth = 100; }
else if (beacon.rssi < 0) { rssiWidth = 100 + beacon.rssi; }
var element = $(
'<li>'
+ '<strong>UUID: ' + beacon.uuid + '</strong><br />'
+ 'Major: ' + beacon.major + '<br />'
+ 'Minor: ' + beacon.minor + '<br />'
+ 'Proximity: ' + beacon.proximity + '<br />'
+ 'RSSI: ' + beacon.rssi + '<br />'
+ 'Distance: ' + beacon.distance + ' m<br />'
+ '<div style="background:rgb(255,128,64);height:20px;width:'
+ rssiWidth + '%;"></div>'
+ '</li>'
);
$('#warning').remove();
$('#found-beacons').append(element);
}
});
}
return app;
})();
app.initialize();
答案 0 :(得分:0)