var app = ( function(){ // Application object. var app = {}; //°´Ã¼¸¦ »ý¼ºÇÏ´Â °Í! // Specify your beacon 128bit UUIDs here. var regions = [ // Estimote Beacon factory UUID. {uuid:'B9407F30-F5F8-466E-AFF9-25556B57FE6D'}, // Sample UUIDs for beacons in our lab. {uuid:'F7826DA6-4FA2-4E98-8024-BC5B71E0893E'}, {uuid:'8DEEFBB9-F738-4297-8040-96668BB44281'}, {uuid:'A0B13730-3A9A-11E3-AA6E-0800200C9A66'}, {uuid:'E20A39F4-73F5-4BC4-A12F-17D1AD07A961'}, {uuid:'A4950001-C5B1-4B44-B512-1370F02D74DE'}, {uuid:'585CDE93-1B01-42CC-9A13-25009BEDC65E'}, // Dialog Semiconductor. ]; // Background detection. var notificationID = 0; var inBackground = false; document.addEventListener('pause', function() { inBackground = true }); //À̺¥Æ® listner document.addEventListener('resume', function() { inBackground = false }); // ºñÄÁ »çÀü var beacons = {}; // ºñÄÁÀǸ®½ºÆ®¸¦ Ç¥½ÃÇϴ ŸÀ̸Ó. var updateTimer = null; app.initialize = function() { document.addEventListener( 'deviceready', function() { evothings.scriptsLoaded(onDeviceReady) }, false); }; function onDeviceReady() { // iBeacon ±â´ÉÀÌÀÖ´Â À§Ä¡ °ü¸®ÀÚÀÇ ¹Ù·Î °¡±â¸¦ ÁöÁ¤ÇϽʽÿÀ. window.locationManager = cordova.plugins.locationManager; // ºñÄÁÃßÀû ½ÃÀÛ startScan(); // »õ·Î °íħ ŸÀ̸Ӹ¦ Ç¥½ÃÇÕ´Ï´Ù. updateTimer = setInterval(displayBeaconList, 500); } function startScan(){ // The delegate iBeacon Äݹé ÇÔ¼ö¸¦ Æ÷ÇÔÇÕ´Ï´Ù. // ¾Æ·¡¿¡ ¸í½ÃµÇ¾î ÀÖ½À´Ï´Ù. var delegate = new locationManager.Delegate(); // ºñÄÜ¿¡ µµ´Þ ÇÒ ¶§ °è¼Ó È£ÃâµË´Ï´Ù. delegate.didRangeBeaconsInRegion = function(pluginResult) { //console.log('didRangeBeaconsInRegion: ' + JSON.stringify(pluginResult)) for (var i in pluginResult.beacons) { // Insert beacon into table of found 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) { if (inBackground) { // ½ÅÈ£°¡ ÇØ´ç Áö¿ª ³»¿¡ ÀÖÀ¸¸é ¾Ë¸²À» Ç¥½ÃÇÕ´Ï´Ù. // TODO: Add check for specific beacon(s) in your app. ¾ÛÀÇ Æ¯Á¤ ½ÅÈ£¸¦ È®ÀÎ if (pluginResult.region.typeName == 'BeaconRegion' && pluginResult.state == 'CLRegionStateInside') { cordova.plugins.notification.local.schedule( { id: ++notificationID, title: 'ºñÄÁÀÌ ¹üÀ§³»¿¡ ÀÖ½À´Ï´Ù.', text: 'ãÀº ºñÄÁÀº ¾ÛÀ¸·Î À̵¿Çؼ­ È®ÀÎÇϼ¼¿ä' }); } } }; // Set the delegate object to use. locationManager.setDelegate(delegate); // »ç¿ëÀÚ°¡ À§Ä¡ Á¤º¸¿¡ ¾×¼¼½º ÇÒ ¼öÀÖ´Â ±ÇÇÑÀ» ¿äûÇϽʽÿÀ. // This is needed on iOS 8. locationManager.requestAlwaysAuthorization(); // ¸ð´ÏÅ͸µ°ú °Å¸®ÃøÁ¤ ½ÃÀÛ for (var i in regions) { var beaconRegion = new locationManager.BeaconRegion( i + 1, regions[i].uuid); // °Å¸® ÃøÁ¤À» ½ÃÀÛÇϽʽÿÀ. locationManager.startRangingBeaconsInRegion(beaconRegion) .fail(console.error) .done(); // ¸ð´ÏÅ͸µ½ÃÀÛ // (ÀÌ ¿¹Á¦¿¡¼­´Â »ç¿ëµÇÁö ¾Ê¾ÒÀ¸¸ç ÂüÁ¶·Î Æ÷ÇԵǾî ÀÖ½À´Ï´Ù.) locationManager.startMonitoringForRegion(beaconRegion) .fail(console.error) .done(); } } function displayBeaconList() { // ºñÄÁ¸®½ºÆ® Á¤¸® //$('#found-beacons').empty(); $('#found-beacons1').empty(); $('#found-beacons2').empty(); $('#found-beacons3').empty(); var timeNow = Date.now(); // ¾÷µ¥ÀÌÆ®µÈ ºñÄÜ ¸®½ºÆ® $.each(beacons, function(key, beacon) { // ¾÷µ¥ÀÌÆ® µÈ ºñÄÁ¸¸ Ç¥½Ã if (beacon.timeStamp + 60000 > timeNow) { // Ç¥½Ã±â¿¡ ´ëÇÑ RSSI °ªÀ» ¹éºÐÀ²·Î Ç¥½ÃÇϽʽÿÀ. var rssiWidth = 1; // RSSI°¡ 0 ÀÌ»óÀÏ ¶§ »ç¿ë if (beacon.rssi < -100) { rssiWidth = 100; } else if (beacon.rssi < 0) { rssiWidth = 100 + beacon.rssi; } var txpower = -72; var distance = ((Math.pow(10,txpower-beacon.rssi))/20.0).toFixed(2); var buuid = beacon.uuid; var bmajor = beacon.major; var bminor = beacon.minor; if(bmajor==42416 && bminor==2288){ $('#found-beacons1').append('
ÅÂÁÖÀÇ ICE Beacon
'); $('#found-beacons1_ul').html(""); var element1 = $( '
  • ' + 'UUID: ' + beacon.uuid + '
    ' + 'Major: ' + beacon.major + '
    ' + 'Minor: ' + beacon.minor + '
    ' + 'Proximity: ' + beacon.proximity + '
    ' + 'RSSI: ' + beacon.rssi + '
    ' + 'distance: ' + distance + '
    ' + '
    ' + '
  • ' ); } if(bmajor==64654 && bminor==11757){ $('#found-beacons2').append('
    Áö¼öÀÇ Mint Beacon
    '); $('#found-beacons2_ul').html(""); var element2 = $( '
  • ' + 'UUID: ' + beacon.uuid + '
    ' + 'Major: ' + beacon.major + '
    ' + 'Minor: ' + beacon.minor + '
    ' + 'Proximity: ' + beacon.proximity + '
    ' + 'RSSI: ' + beacon.rssi + '
    ' + 'distance: ' + distance + '
    ' + '
    ' + '
  • ' ); } if(bmajor==56135 && bminor==45314){ $('#found-beacons3').append('
    »ó¸ñÀÌÀÇ Blueberry Beacon
    '); $('#found-beacons3_ul').html(""); var element3 = $( '
  • ' + 'UUID: ' + beacon.uuid + '
    ' + 'Major: ' + beacon.major + '
    ' + 'Minor: ' + beacon.minor + '
    ' + 'Proximity: ' + beacon.proximity + '
    ' + 'RSSI: ' + beacon.rssi + '
    ' + 'distance: ' + distance + '
    ' + '
    ' + '
    ' + '
  • ' ); } /* // ºñÄÜ µ¥ÀÌÅ͸¦ Ç¥½Ã ÇÒ Å±׸¦ ¸¸µë var element = $( '
  • ' + 'UUID: ' + beacon.uuid + '
    ' + 'Major: ' + beacon.major + '
    ' + 'Minor: ' + beacon.minor + '
    ' + 'Proximity: ' + beacon.proximity + '
    ' + 'RSSI: ' + beacon.rssi + '
    ' + '
    ' + '
  • ' ); //'
    ' */ $('#warning').remove(); if(n1==1){ $('#found-beacons1').append(element1); } if(n2==1){ $('#found-beacons2').append(element2); } if(n3==1){ $('#found-beacons3').append(element3); } } }); } ////////////////////////////////////////////////////////////////////////////////////////////////////////// /* // Note: This example requires that you consent to location sharing when // prompted by your browser. If you see the error "The Geolocation service // failed.", it means you probably did not give permission for the browser to // locate you. function initMap() { var map = new google.maps.Map(document.getElementById('map'), { center: {lat: -34.397, lng: 150.644}, zoom: 10 }); var infoWindow = new google.maps.InfoWindow({map: map}); // Try HTML5 geolocation. if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var pos = { lat: position.coords.latitude, lng: position.coords.longitude }; infoWindow.setPosition(pos); infoWindow.setContent('Location found.'); map.setCenter(pos); }, function() { handleLocationError(true, infoWindow, map.getCenter()); }); } else { // Browser doesn't support Geolocation handleLocationError(false, infoWindow, map.getCenter()); } } function handleLocationError(browserHasGeolocation, infoWindow, pos) { infoWindow.setPosition(pos); infoWindow.setContent(browserHasGeolocation ? 'Error: The Geolocation service failed.' : 'Error: Your browser doesn\'t support geolocation.'); } */ /////////////////////////////////////////////////////////////////////////////////////////////////////////// window.onload=init1; var n1,n2,n3=0; function init1() { var button1 = document.getElementById("found-beacons1"); // ¾ÆÀ̵𸦠ÀÌ¿ëÇÏ¿©¼­ ¹öưÀÇ Á¤º¸¸¦ ¾ò°í button1.onclick = handleButtonClick1; // ¹öư Ŭ¸¯½Ã¿¡ handleButtonClickÀ» È£ÃâÇÏ°Ô ÇÔ. var button2 = document.getElementById("found-beacons2"); // ¾ÆÀ̵𸦠ÀÌ¿ëÇÏ¿©¼­ ¹öưÀÇ Á¤º¸¸¦ ¾ò°í button2.onclick = handleButtonClick2; // ¹öư Ŭ¸¯½Ã¿¡ handleButtonClickÀ» È£ÃâÇÏ°Ô ÇÔ. var button3 = document.getElementById("found-beacons3"); // ¾ÆÀ̵𸦠ÀÌ¿ëÇÏ¿©¼­ ¹öưÀÇ Á¤º¸¸¦ ¾ò°í button3.onclick = handleButtonClick3; // ¹öư Ŭ¸¯½Ã¿¡ handleButtonClickÀ» È£ÃâÇÏ°Ô ÇÔ. } function handleButtonClick1(e) { if(n1==0){ n1=1; } else{ n1=0; } } function handleButtonClick2(e) { if(n2==0){ n2=1; } else{ n2=0; } } function handleButtonClick3(e) { if(n3==0){ n3=1; } else{ n3=0; } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// return app; })(); app.initialize();