2010-04-01 55 views
7

知道在Safari中使用JavaScript訪問iPhone指南針是否可行?我看到how the GPS can be accessed,但我無法弄清楚指南針。使用JavaScript訪問iPhone指南針

謝謝,一如既往!

+1

只注意到今天發表的這份W3C指南針API草案:http://dev.w3.org/2009/dap/system-info/compass.html所以,也許這種功能將會有所不同。 – 2010-04-01 23:23:55

+0

在iOS5中,您可以通過webkitCompassHeading 訪問指南針,請查看[本文檔](https://developer.apple.com/library/safari/#documentation/SafariDOMAdditions/Reference/DeviceOrientationEventClassRef/DeviceOrientationEvent/DeviceOrientationEvent.html#//apple_ref/javascript/instp/DeviceOrientationEvent/webkitCompassHeading) – 2011-10-13 18:09:04

回答

3
+0

謝謝,很高興知道。 – 2010-04-01 23:23:01

+1

這個答案不再是真的,iOS 4.2提供了webkitCompassHeading,看看awoodland的答案 – ianj 2011-10-25 19:35:07

3

的iOS,您可以檢索指南針值這個樣子。

window.addEventListener('deviceorientation', function(e) { 
    console.log(e.webkitCompassHeading); 
}, false); 

有關更多信息,請閱讀Apple DeviceOrientationEvent文檔。

希望這有助於。