我正在尝试为罗盘标题获取单个精确值(然后我使用陀螺仪/加速度计来计算偏差)。
麻烦的是,如果我在第一个结果后停止更新标题,我的标题值为0.0?
我知道有些位置服务需要运行一段时间才能给出准确的结果,但是如何为newHeading.magneticHeading实现这个?
任何提示? (我正在使用CoreLocation和CLLocation Manager)
func locationManager(manager: CLLocationManager,
didUpdateHeading newHeading: CLHeading) {
referenceHeading = newHeading.magneticHeading
print("New reference heading = \(newHeading.magneticHeading)")
gotReferenceHeading = true
locationManager.stopUpdatingHeading()
}
答案 0 :(得分:0)
我添加了一个基于headingAccuracy的if语句,正如@jtbandes所建议的那样。
var html = '<p><img class="alignnone size-full wp-image-2857" src="https://files.wordpress.com/2016/05/laptop.jpg?w=750&h=545" alt="https://pixabay.com/en/laptop-printer-office-folder-graph-1016257/" width=\"750" height="545" /></p> <p>STUFF</p> <p>MORE STUFF</p> <p>EVEN MORE STUFF</p> <p><strong><span style="text-decoration:underline;">OTHER STUFF</span></strong></p> <p><em>OTHER STUFF</em>: DEMO STUFF</p> <p><em>TEST STUFF</em>: WRAP UP STUFF</p> <p><strong><span style="text-decoration:underline;">REST OF STUFF</span></strong></p> <p><em>Aloha POS</em>: KEEP THIS STUFF TOO</p> <p><em>Revel</em>: WHAT STUFF</p> <p>DONE</p>';
var el = document.createElement('div');
el.innerHTML = html;
var p = el.getElementsByTagName('p')[0]; // the first one where the image is
var img = p.getElementsByTagName('img')[0]; // there is only one might want to use id or class to be more specific
console.log(img);
p.removeChild(img); //have to remove from the first ancestor or parent
所以我只是继续接收标题更新,直到我得到有用的结果。