{"id":161,"date":"2019-08-05T17:22:44","date_gmt":"2019-08-05T09:22:44","guid":{"rendered":"https:\/\/www.hlzhy.com\/?p=161"},"modified":"2021-03-11T09:47:46","modified_gmt":"2021-03-11T01:47:46","slug":"ios-ibeacon%e5%ae%a4%e5%86%85%e5%ae%9a%e4%bd%8d%e4%b9%8b%e5%88%86%e6%ad%a5%e5%ae%9a%e4%bd%8d%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.hlzhy.com\/?p=161","title":{"rendered":"iOS iBeacon\u5ba4\u5185\u5b9a\u4f4d\u4e4b\u5206\u6b65\u5b9a\u4f4d\u6cd5"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"776\" src=\"https:\/\/www.hlzhy.com\/wp-content\/uploads\/2019\/08\/iBeacon1-1024x776.png\" alt=\"\" class=\"wp-image-165\" srcset=\"https:\/\/www.hlzhy.com\/wp-content\/uploads\/2019\/08\/iBeacon1-1024x776.png 1024w, https:\/\/www.hlzhy.com\/wp-content\/uploads\/2019\/08\/iBeacon1-300x227.png 300w, https:\/\/www.hlzhy.com\/wp-content\/uploads\/2019\/08\/iBeacon1-768x582.png 768w, https:\/\/www.hlzhy.com\/wp-content\/uploads\/2019\/08\/iBeacon1.png 1050w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8bf4\u5230\u5b9a\u4f4d\u7b97\u6cd5\uff0c\u4e00\u822c\u6211\u4eec\u7b2c\u4e00\u4e2a\u60f3\u5230\u7684\u65b9\u6848\u5c31\u662f\u4e09\u8fb9\u6d4b\u91cf\u6cd5\uff08Trilateration\uff09\uff0c\u901a\u8fc7\u4e09\u4e2a\u4fe1\u53f7\u70b9\uff08Beacons\uff09\u548c\u5206\u522b\u5bf9\u5e94\u7684\u8ddd\u79bb\uff0c\u5f62\u6210\u4e09\u4e2a\u5706\u5e76\u76f8\u4ea4\u4e8e\u4e00\u70b9\u3002\u4f46\u662f\u5b9e\u9645\u60c5\u51b5\u5e76\u6ca1\u6709\u90a3\u4e48\u7406\u60f3\u5316\uff0c\u6709\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e24\u5706\u4e0d\u76f8\u4ea4\u3001\u5706\u5305\u542b\u5706\u3001\u53ea\u6709\u4e24\u4e2a\u4fe1\u53f7\u70b9\u6216\u8005\u591a\u4e2a\u4fe1\u53f7\u70b9\u6392\u6210\u4e00\u5217\u7684\u60c5\u51b5\uff08\u8fc7\u9053\u91cc\uff09\uff0c\u8fd9\u90fd\u662f\u4e00\u4e9b\u6bd4\u8f83\u5e38\u89c1\u7684\u573a\u666f\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u80fd\u540c\u65f6\u89e3\u51b3\u4e0a\u9762\u8fd9\u4e9b\u95ee\u9898\u7684\u8ba1\u7b97\u65b9\u6cd5\u2014\u2014<a href=\"https:\/\/wenku.baidu.com\/view\/1b5f7d3c8e9951e79b892773.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u5206\u6b65\u5b9a\u4f4d\u6cd5<\/a>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5206\u6b65\u5b9a\u4f4d\u6cd5<\/h3>\n\n\n\n<p>\u5728iOS\u5f00\u53d1\u4e2d\uff0c\u4f7f\u7528<code>CLLocationManager<\/code>\u7684<code>startRangingBeaconsInRegion:<\/code>\u65b9\u6cd5\u76d1\u542cBeacons\uff0c\u5e76\u901a\u8fc7\u4ee3\u7406\u56de\u8c03\u4e2d\u83b7\u5f97Beacons\u5217\u8868\u3002\u53d6\u51fa<code>rssi<\/code>\u4fe1\u53f7\u503c\u6700\u5f3a\u7684\u4e09\u4e2a\u70b9\uff0c\u53d6<code>accuracy<\/code>\u503c\u4f5c\u4e3a\u5706\u534a\u5f84\uff08\u9700\u8981\u51cf\u53bb\u9ad8\u5ea6\u5dee\uff09\uff0c\u7528<code>major<\/code>\u3001<code>minor<\/code>\u503c\u4ece\u540e\u53f0\u8fd4\u56de\u7684\u6570\u636e\u4e2d\u53d6\u51fa\u5bf9\u5e94\u7684\u5750\u6807\u70b9\u6570\u636e\u5373\u4e3a\u4e09\u4e2a\u5706\u7684\u5706\u5fc3\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"864\" src=\"https:\/\/www.hlzhy.com\/wp-content\/uploads\/2019\/08\/iBeacon2-1024x864.png\" alt=\"\" class=\"wp-image-166\" srcset=\"https:\/\/www.hlzhy.com\/wp-content\/uploads\/2019\/08\/iBeacon2-1024x864.png 1024w, https:\/\/www.hlzhy.com\/wp-content\/uploads\/2019\/08\/iBeacon2-300x253.png 300w, https:\/\/www.hlzhy.com\/wp-content\/uploads\/2019\/08\/iBeacon2-768x648.png 768w, https:\/\/www.hlzhy.com\/wp-content\/uploads\/2019\/08\/iBeacon2.png 1436w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>\u56fe1-1\uff0c\u5206\u6b65\u5b9a\u4f4d\u6cd5<\/figcaption><\/figure>\n\n\n\n<p>\u8be5\u7b97\u6cd5\u6bd4\u8f83\u7b80\u5355\uff0c\u5982\u56fe1-1\uff0c\u4e0d\u76f8\u4ea4\u65f6\uff0c\u6309\u6bd4\u4f8b\u53d6\u4e2d\u70b9\uff08OAZ\u548cOBZ\uff09\u3002\u5f53\u4e24\u5706\u76f8\u4ea4\u65f6\uff0c\u5c31\u662f\u62c6\u5206\u6210\u51e0\u4e2a\u4e09\u89d2\u5f62\uff0c\u901a\u8fc7\u4e00\u7cfb\u5217\u4e09\u7ea7\u51fd\u6570\u8ba1\u7b97\u51fa\u672a\u77e5\u7684\u4e24\u4e2a\u4ea4\u70b9\u3002\u6700\u540e\u5c06\u4e09\u70b9\u8fde\u6210\u4e09\u89d2\u5f62\uff0c\u6b64\u4e09\u89d2\u5f62\u7684\u91cd\u5fc3\uff08\u5373\u70b9M\uff09\u5c31\u662f\u6700\u7ec8\u5b9a\u4f4d\u70b9\uff0c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ol><li>\u901a\u8fc7\u52fe\u80a1\u5b9a\u5f8b\u7528a\u3001b\u957f\u5ea6\u8ba1\u7b97\u51fa\u7ebf\u6bb5AB\u957f\u5ea6\uff08\u5373\u70b9A\u5230\u70b9B\u8ddd\u79bb\uff09\uff0c\u4f7f\u7528 ra + rb \u4e0eAB\u5bf9\u6bd4\u5373\u53ef\u5f97\u77e5\u4e24\u5706\u7684\u5bf9\u5e94\u60c5\u51b5\uff0c\u4e00\u5171\u6709\u4e09\u79cd\u60c5\u51b5\uff1a\u4e24\u5706\u76f8\u79bb<code>ra + rb &lt; AB<\/code>\u3001\u4e24\u5706\u76f8\u5207<code>ra + rb == AB<\/code>\u3001\u4e24\u5706\u76f8\u4ea4<code>ra + rb &gt; AB<\/code>\u3002<\/li><li>\u4e24\u5706\u76f8\u79bb\uff1a\u6309\u7167\u4e24\u5706\u534a\u5f84\u7684\u6bd4\u4f8b\u5728\u7ebf\u6bb5AZ\u4e0a\u6c42O<font size=\"1.0\">AZ<\/font>\u70b9\uff0c\u5373 ra : rz = |AO<font size=\"1.0\">AZ<\/font>| : |O<font size=\"1.0\">AZ<\/font>Z|\uff1b\u201c\u4e24\u5706\u76f8\u5207\u201d\u4f7f\u7528\u201c\u4e24\u5706\u76f8\u79bb\u201d\u76f8\u540c\u7684\u6c42\u6cd5\u5373\u53ef\u3002<\/li><li>\u4e24\u5706\u76f8\u4ea4\uff1a\u6c42\u51fa\u76f8\u4ea4\u70b9C\u7684\u5750\u6807 {Cx, Cy}\uff0c\u53ef\u901a\u8fc7arccos( a \/ AB )\u5f97\u51faQ1\uff0c\u901a\u8fc7arccos( AO<font size=\"1.0\">AB<\/font> \/ ra )\u5f97\u51faQ2\uff0c\u6700\u540e\u8ba1\u7b97\u51fa\u70b9C\u7684\u5750\u6807\uff1a<br>Cx = Ax + (ra + cos(Q1+Q2))<br>Cy = Ay + (ra + sin(Q1+Q2))<br>\u540c\u7406\u53ef\u6c42\u51fa\u70b9D\u7684\u5750\u6807\u3002\u5f97\u5230C\u3001D\u4e24\u4ea4\u70b9\u540e\u53d6\u8ddd\u79bb\u5706\u5fc3Z\u70b9\u8fd1\u7684\u4ea4\u70b9\u4f5c\u4e3a\u6700\u540e\u4e09\u4e2a\u53c2\u8003\u70b9\u4e2d\u7684\u4e00\u70b9\u3002<\/li><li>\u5c06\u6700\u540e\u6c42\u5f97\u7684\u4e09\u4e2a\u53c2\u8003\u70b9\u8fde\u63a5\u6210\u4e00\u4e2a\u4e09\u89d2\u5f62\uff0c\u8be5\u4e09\u89d2\u5f62\u7684\u91cd\u5fc3\u5373\u4e3a\u6700\u540e\u7684\u5b9a\u4f4d\u70b9M\uff1a<br>Mx = (Dx + O<font size=\"1.0\">AZ<\/font>x + O<font size=\"1.0\">BZ<\/font>x) \/ 3<br>My = (Dy + O<font size=\"1.0\">AZ<\/font>y + O<font size=\"1.0\">BZ<\/font>y) \/ 3<\/li><\/ol>\n\n\n\n<p>\u91c7\u7528\u5206\u6b65\u5b9a\u4f4d\u6cd5\u6d4b\u91cf\u4e00\u4e2a\u79fb\u52a8\u8282\u70b9\u7684\u4f4d\u7f6e\uff0c\u53ea\u9700\u89813\u4e2a\u53c2\u8003\u8282\u70b9\u3002\u8be5\u5b9a\u4f4d\u6cd5\u8fd8\u907f\u514d\u4e86\u91c7\u7528\u4e09\u8fb9\u6d4b\u91cf\u6cd5\u53ef\u80fd\u65e0\u89e3\u7684\u60c5\u51b5\uff0c\u4f7f\u5f97\u8be5\u65b9\u6cd5\u7684\u9002\u5e94\u6027\u66f4\u5f3a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u76f8\u5173\u4ee3\u7801<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>    CGPoint pointA = &#91;self sidePointCalculationWith:x1 :y1 :r1\n                                                   :x2 :y2 :r2\n                                                   :x3 :y3 ];\n    CGPoint pointB = &#91;self sidePointCalculationWith:x2 :y2 :r2\n                                                   :x3 :y3 :r3\n                                                   :x1 :y1 ];\n    CGPoint pointC = &#91;self sidePointCalculationWith:x1 :y1 :r1\n                                                   :x3 :y3 :r3\n                                                   :x2 :y2 ];\n \n    double Mx = (pointA.x + pointB.x + pointC.x) \/ 3;\n    double My = (pointA.y + pointB.y + pointC.y) \/ 3;\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-(CGPoint)sidePointCalculationWith:(double)x1 :(double)y1 :(double)r1 \n                                  :(double)x2 :(double)y2 :(double)r2 \n                                  :(double)x3 :(double)y3{\n    \/\/\u52fe\u80a1\u5b9a\u7406  sqrt(X)\u662fX\u5f00\u6839\u53f7  pow\uff08X,n\uff09\u662fX\u7684n\u6b21\u65b9\n    \/\/\u53d6beacon1\u5706\u5fc3A \u4e0e beacon2\u5706\u5fc3B\u7684\u8ddd\u79bb\n    double AB = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));\n    double rAB = (r1 + r2);\n    if (rAB &gt; AB &amp;&amp; (r1 &lt; AB &amp;&amp; r2 &lt; AB)) {\n        \/\/\u4e24\u5706\u6709\u76f8\u4ea4\u70b9,\u4e24\u5706\u76f8\u4ea4\u70b9\u4e3aC\u3001D\u3002\u4e24\u5706\u4e0eAB\u7684\u76f8\u4ea4\u70b9\u4e3aE\u3001F\u3002o\u662fEF\u7684\u4e2d\u70b9\u3002\n        double EF = rAB - AB;\n        double Eo = EF * 0.5;\n        double AE = r1 - EF;\n        double Ao = AE + Eo;\n        double AQ1 = acos((x2 - x1) \/ AB);\n        double AQ2 = acos(Ao \/ r1);\n        \n        double BF = r2 - EF;\n        double Bo = BF + Eo;\n\/\/        double BQ1 = acos(fabs(x1 - x2) \/ AB);\n        double BQ2 = acos(Bo \/ r2);\n        \n        \/\/\u539f\u70b9{0,0}\u5728\u5de6\u4e0a\u89d2\u7684\u60c5\u51b5\u4e0b\n        double Cx = x1 + (r1 * cos(AQ1 + AQ2));\n        double Cy = 0.0;\n        double Dx = x2 - (r2 * cos(AQ1 + BQ2));\n        double Dy = 0.0;\n        if (x1 &lt; x2) {\n            Dx = x2 - (r2 * cos(AQ1 + BQ2));\n            if (y1 &lt; y2) {\n                Cy = y1 + (r1 * sin(AQ1 + AQ2));\n                Dy = y2 - (r2 * sin(AQ1 + BQ2));\n            }else{\n                Cy = y1 - (r1 * sin(AQ1 + AQ2));\n                Dy = y2 + (r2 * sin(AQ1 + BQ2));\n            }\n        }else{\n            Cy = y1 + (r1 * sin(AQ1 + AQ2));\n            if (y1 &lt; y2) {\n                Dy = y2 - (r2 * sin(AQ1 + BQ2));\n            }else{\n                Dy = y2 + (r2 * sin(AQ1 + BQ2));\n            }\n        }\n        \n        double Cc = sqrt(pow(Cx - x3, 2) + pow(Cy - y3, 2));\n        double Dc = sqrt(pow(Dx - x3, 2) + pow(Dy - y3, 2));\n\n        return Cc &lt; Dc ? CGPointMake(Cx, Cy) : CGPointMake(Dx, Dy);\n    }else{\n        \/\/\u4e24\u5706\u65e0\u76f8\u4ea4\u70b9\n        return &#91;self midpointCalculationWith:x1 :y1 :r1\n                                            :x2 :y2 :r2];\n    }\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-(CGPoint)midpointCalculationWith:(double)x1 :(double)y1 :(double)r1 \n                                 :(double)x2 :(double)y2 :(double)r2{\n    double a = y1 - y2;\/\/\u7ad6\u8fb9\n    double b = x1 - x2;\/\/\u6a2a\u8fb9\n    double rr = r1 + r2;\n    double s = r1 \/ rr;\n    \n    double x = fabs(x1 - (b * s)) ;\n    double y = fabs(y1 - (a * s)) ;\n    \n    return CGPointMake(x, y);\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u53c2\u8003\u8d44\u6599<\/h3>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fwenku.baidu.com%2Fview%2F1b5f7d3c8e9951e79b892773.html\" target=\"_blank\">\u4e09\u8fb9\u6d4b\u91cf\u6cd5,\u5206\u6b65\u5b9a\u4f4d\u6cd5\u6bd4\u8f83<\/a><br><a rel=\"noreferrer noopener\" href=\"https:\/\/links.jianshu.com\/go?to=http%3A%2F%2Fpingguohe.net%2F2018%2F02%2F01%2Fibeacon.html\" target=\"_blank\">\u82f9\u679c\u6838 &#8211; iOS\u7aef\u8fd1\u573a\u56f4\u680f\u68c0\u6d4b\uff08\u4e00\uff09 \u2014\u2014iBeacon<\/a><br><a rel=\"noreferrer noopener\" href=\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fsevencho.github.io%2Farchives%2Fb05dc691.html\" target=\"_blank\">iOS\u84dd\u7259\u5f00\u53d1\u4e4biBeacon\u7bc7(\u4e8c)<\/a><\/p>\n\n\n\n<p>&#8212;END&#8212;<\/p>\n\n\n\n<p><a href=\"https:\/\/www.hlzhy.com\/?p=161\">\u539f\u6587\u5730\u5740\uff1a<\/a><a rel=\"noreferrer noopener\" target=\"_blank\" href=\"https:\/\/www.hlzhy.com\/?p=161\">https:\/\/www.hlzhy.com\/?p=161<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>\u8bf4\u5230\u5b9a\u4f4d\u7b97\u6cd5\uff0c\u4e00\u822c\u6211\u4eec\u7b2c\u4e00\u4e2a\u60f3\u5230\u7684\u65b9\u6848\u5c31\u662f\u4e09\u8fb9\u6d4b\u91cf\u6cd5\uff08Trilateration\uff09\uff0c\u901a\u8fc7\u4e09\u4e2a\u4fe1\u53f7\u70b9\uff08Beacons\uff09\u548c\u5206\u522b\u5bf9\u5e94\u7684\u8ddd\u79bb\uff0c\u5f62\u6210\u4e09 &hellip; <a href=\"https:\/\/www.hlzhy.com\/?p=161\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">iOS iBeacon\u5ba4\u5185\u5b9a\u4f4d\u4e4b\u5206\u6b65\u5b9a\u4f4d\u6cd5<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/posts\/161"}],"collection":[{"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=161"}],"version-history":[{"count":8,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions\/191"}],"wp:attachment":[{"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}